2016-11-11 18:08:40 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
2016-11-16 18:42:13 +00:00
|
|
|
type _SourceMap = {
|
|
|
|
version: number,
|
|
|
|
file: string,
|
|
|
|
sources: Array<string>,
|
|
|
|
names: Array<string>,
|
|
|
|
mappings: string,
|
|
|
|
sourcesContent: Array<string>,
|
|
|
|
};
|
|
|
|
|
2016-11-11 18:08:40 +00:00
|
|
|
// based on babylon v6.13.1
|
|
|
|
type BabylonOptions = {
|
|
|
|
allowImportExportEverywhere?: boolean,
|
|
|
|
allowReturnOutsideFunction?: boolean,
|
|
|
|
allowSuperOutsideMethod?: boolean,
|
|
|
|
sourceType?: 'script' | 'module',
|
|
|
|
sourceFilename?: 'string',
|
|
|
|
plugins?: Array<
|
|
|
|
'jsx' | 'flow' | 'doExpressions' | 'objectRestSpread' | 'decorators' |
|
|
|
|
'classProperties' | 'exportExtensions' | 'asyncGenerators' |
|
|
|
|
'functionBind' | 'functionSent' | 'dynamicImport'
|
|
|
|
>,
|
|
|
|
};
|
|
|
|
|
|
|
|
// based on babel-generator v6.18.0
|
|
|
|
type GeneratorOptions = {
|
|
|
|
auxiliaryCommentBefore?: string,
|
|
|
|
auxiliaryCommentAfter?: string,
|
|
|
|
shouldPrintComment?: (comment: string) => boolean,
|
|
|
|
retainLines?: boolean,
|
|
|
|
retainFunctionParens?: boolean,
|
|
|
|
comments?: boolean,
|
|
|
|
compact?: boolean | 'auto',
|
|
|
|
minified?: boolean,
|
|
|
|
concise?: boolean,
|
|
|
|
quotes?: 'single' | 'double',
|
|
|
|
filename?: string,
|
|
|
|
sourceMaps?: boolean,
|
|
|
|
sourceMapTarget?: string,
|
|
|
|
sourceRoot?: string,
|
|
|
|
sourceFileName?: string,
|
|
|
|
};
|
|
|
|
|
2016-11-16 18:42:13 +00:00
|
|
|
type InlinePlugin = [() => {}, {}];
|
|
|
|
|
2016-11-11 18:08:40 +00:00
|
|
|
// based on https://babeljs.io/docs/usage/options/ -- 2016-11-11
|
|
|
|
type _TransformOptions = {
|
|
|
|
filename?: string,
|
|
|
|
filenameRelative?: string,
|
|
|
|
presets?: Array<string | Object>,
|
2016-11-16 18:42:13 +00:00
|
|
|
plugins?: Array<string | Object | InlinePlugin>,
|
2016-11-11 18:08:40 +00:00
|
|
|
parserOpts?: BabylonOptions,
|
|
|
|
generatorOpts?: GeneratorOptions,
|
|
|
|
highlightCode?: boolean,
|
|
|
|
only?: string | RegExp | Array<string | RegExp>,
|
|
|
|
ignore?: string | RegExp | Array<string | RegExp>,
|
|
|
|
auxiliaryCommentBefore?: boolean,
|
|
|
|
auxiliaryCommentAfter?: boolean,
|
|
|
|
sourceMaps?: boolean,
|
2016-11-16 18:42:13 +00:00
|
|
|
inputSourceMap?: ?Object,
|
2016-11-11 18:08:40 +00:00
|
|
|
sourceMapTarget?: string,
|
|
|
|
sourceFileName?: string,
|
|
|
|
sourceRoot?: string,
|
|
|
|
moduleRoot?: string,
|
|
|
|
moduleIds?: boolean,
|
|
|
|
moduleId?: string,
|
|
|
|
getModuleId?: (moduleName: string) => string,
|
|
|
|
resolveModuleSource?: (source: string, filename: string) => string,
|
|
|
|
code?: boolean,
|
|
|
|
babelrc?: boolean,
|
|
|
|
ast?: boolean,
|
|
|
|
compact?: boolean | 'auto',
|
|
|
|
minified?: boolean,
|
|
|
|
comments?: boolean,
|
|
|
|
shouldPrintComment?: (comment: string) => boolean,
|
|
|
|
retainLines?: boolean,
|
|
|
|
extends?: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
type TransformOptions =
|
|
|
|
_TransformOptions & {env?: {[key: string]: TransformOptions}};
|
2016-11-16 18:42:13 +00:00
|
|
|
declare class _Ast {};
|
|
|
|
type TransformResult = {
|
|
|
|
ast: ?_Ast,
|
|
|
|
code: ?string,
|
|
|
|
map: ?_SourceMap,
|
|
|
|
};
|
2016-11-11 18:08:40 +00:00
|
|
|
type VisitFn = <State>(path: Object, state: State) => any;
|
|
|
|
|
|
|
|
declare module 'babel-core' {
|
2016-11-16 18:42:13 +00:00
|
|
|
declare type SourceMap = _SourceMap;
|
|
|
|
declare type Ast = _Ast;
|
2016-11-11 18:08:40 +00:00
|
|
|
declare function transform(
|
|
|
|
code: string,
|
|
|
|
options?: TransformOptions,
|
|
|
|
): TransformResult;
|
|
|
|
declare function traverse<State>(
|
2016-11-16 18:42:13 +00:00
|
|
|
ast: _Ast,
|
2016-11-11 18:08:40 +00:00
|
|
|
visitor: {[key: string]: VisitFn<State> |
|
|
|
|
{enter?: VisitFn<State>, exit?: VisitFn<State>}},
|
|
|
|
scope?: ?Object,
|
|
|
|
state?: State,
|
|
|
|
parentPath?: ?Object,
|
|
|
|
): void;
|
|
|
|
declare var types: {[key: string]: Function};
|
2016-11-16 18:42:13 +00:00
|
|
|
declare function transformFromAst(
|
|
|
|
ast: _Ast,
|
|
|
|
code?: ?string,
|
|
|
|
babelOptions?: TransformOptions,
|
|
|
|
): TransformResult;
|
2016-11-11 18:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
declare module 'babel-generator' {
|
|
|
|
declare function exports(
|
2016-11-16 18:42:13 +00:00
|
|
|
ast: _Ast,
|
2016-11-11 18:08:40 +00:00
|
|
|
options?: GeneratorOptions,
|
|
|
|
): {ast: Object, code: string, map: Object};
|
|
|
|
}
|