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

View File

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

View File

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