Fix source maps output option in CLI (#536)

This commit is contained in:
Sebastian Markbåge 2017-05-04 18:09:07 -07:00 committed by GitHub
parent eb8268a7e0
commit 2e0ff63a69
3 changed files with 17 additions and 3 deletions

View File

@ -15,8 +15,15 @@
import { BabelNode } from "babel-types";
type SourceMap = {
sources: Array<string>,
names: Array<string>,
mappings: string,
sourcesContent: Array<string>
};
declare module 'babel-generator' {
declare module.exports: (ast: BabelNode, opts: Object, code: string) => { code: string, map?: string };
declare module.exports: (ast: BabelNode, opts: Object, code: string) => { code: string, map?: SourceMap };
}
/**

View File

@ -101,7 +101,7 @@ if (!inputFilename) {
}
if (outputSourceMap) {
fs.writeFileSync(outputSourceMap, serialized.map || "");
fs.writeFileSync(outputSourceMap, serialized.map ? JSON.stringify(serialized.map) : '');
}
} catch (x) {
if (x instanceof InitializationError) {

View File

@ -31,6 +31,13 @@ import { Logger } from "./logger.js";
import { Modules } from "./modules.js";
import { LoggingTracer } from "./LoggingTracer.js";
type SourceMap = {
sources: Array<string>,
names: Array<string>,
mappings: string,
sourcesContent: Array<string>
};
function isSameNode(left, right) {
let type = left.type;
@ -1367,7 +1374,7 @@ export class Serializer {
return false;
}
serialize(filename: string, code: string, sourceMaps: boolean): { generated?: { code: string, map?: string } } {
serialize(filename: string, code: string, sourceMaps: boolean): { generated?: { code: string, map?: SourceMap } } {
this._emitGenerator(this.generator);
invariant(this.declaredDerivedIds.size <= this.preludeGenerator.derivedIds.size);