Fix Flow type for babel-generator

Reviewed By: rafeca

Differential Revision: D6682632

fbshipit-source-id: befc2fe51c8e3b542b0f2b8b595ed78b39bd1801
This commit is contained in:
Peter van der Zee 2018-01-09 03:58:54 -08:00 committed by Facebook Github Bot
parent 1b37017eb1
commit 8815c8329d
3 changed files with 14 additions and 4 deletions

View File

@ -98,6 +98,12 @@ type TransformResult = {
ignored: boolean,
map: ?_SourceMap,
};
// https://github.com/babel/babel/blob/master/packages/babel-generator/src/buffer.js#L42
type GeneratorResult = {
code: string,
map: ?_SourceMap,
rawMappings: ?Array<RawMapping>,
};
type VisitFn = <State>(path: Object, state: State) => any;
declare module 'babel-core' {
@ -132,10 +138,12 @@ type RawMapping = {
source?: string,
};
// https://github.com/babel/babel/tree/master/packages/babel-generator
declare module 'babel-generator' {
declare type RawMapping = RawMapping;
declare module.exports: (
declare module.exports: {default: (
ast: Ast,
options?: GeneratorOptions,
) => TransformResult & {rawMappings: ?Array<RawMapping>};
code?: string | {[string]: string},
) => GeneratorResult};
}

View File

@ -35,7 +35,9 @@ function generate(
sourceCode,
);
delete generated.map.sourcesContent;
if (generated.map) {
delete generated.map.sourcesContent;
}
return generated;
}

View File

@ -90,7 +90,7 @@ function optimize(transformed: TransformResult, file, options) {
const min = minify.withSourceMap(
gen.code,
inputMap && mergeSourceMaps(file, inputMap, gen.map),
inputMap && gen.map && mergeSourceMaps(file, inputMap, gen.map),
file,
);
return {code: min.code, map: min.map, dependencies};