2017-06-09 20:52:06 +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.
|
2018-01-11 11:12:05 +00:00
|
|
|
*
|
|
|
|
* @flow
|
|
|
|
* @format
|
2017-06-09 20:52:06 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-11 12:27:23 +00:00
|
|
|
type _BabelSourceMap = {
|
2017-06-09 20:52:06 +00:00
|
|
|
file?: string,
|
|
|
|
mappings: string,
|
|
|
|
names: Array<string>,
|
|
|
|
sourceRoot?: string,
|
|
|
|
sources: Array<string>,
|
|
|
|
sourcesContent?: Array<?string>,
|
|
|
|
version: number,
|
|
|
|
};
|
|
|
|
|
|
|
|
// based on babylon v6.13.1
|
|
|
|
type BabylonOptions = {
|
|
|
|
allowImportExportEverywhere?: boolean,
|
|
|
|
allowReturnOutsideFunction?: boolean,
|
|
|
|
allowSuperOutsideMethod?: boolean,
|
|
|
|
sourceType?: 'script' | 'module',
|
|
|
|
sourceFilename?: 'string',
|
|
|
|
plugins?: Array<
|
2018-01-11 11:12:05 +00:00
|
|
|
| 'jsx'
|
|
|
|
| 'flow'
|
|
|
|
| 'doExpressions'
|
|
|
|
| 'objectRestSpread'
|
|
|
|
| 'decorators'
|
|
|
|
| 'classProperties'
|
|
|
|
| 'exportExtensions'
|
|
|
|
| 'asyncGenerators'
|
|
|
|
| 'functionBind'
|
|
|
|
| 'functionSent'
|
|
|
|
| 'dynamicImport',
|
2017-06-09 20:52:06 +00:00
|
|
|
>,
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
};
|
|
|
|
|
2018-01-11 11:12:05 +00:00
|
|
|
type InlinePlugin = string | {} | (() => {});
|
2017-06-09 20:52:06 +00:00
|
|
|
type _Plugins = Array<string | Object | [InlinePlugin] | [InlinePlugin, mixed]>;
|
|
|
|
|
|
|
|
// based on https://babeljs.io/docs/usage/options/ -- 2016-11-11
|
|
|
|
type __TransformOptions = {
|
|
|
|
filename?: string,
|
|
|
|
filenameRelative?: string,
|
2017-06-14 16:25:55 +00:00
|
|
|
presets?: _Plugins,
|
2017-06-09 20:52:06 +00:00
|
|
|
plugins?: _Plugins,
|
|
|
|
parserOpts?: BabylonOptions,
|
|
|
|
generatorOpts?: GeneratorOptions,
|
|
|
|
highlightCode?: boolean,
|
|
|
|
only?: string | RegExp | Array<string | RegExp>,
|
|
|
|
ignore?: string | RegExp | Array<string | RegExp>,
|
|
|
|
auxiliaryCommentBefore?: boolean,
|
|
|
|
auxiliaryCommentAfter?: boolean,
|
|
|
|
sourceMaps?: boolean,
|
|
|
|
inputSourceMap?: ?Object,
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2018-01-11 11:12:05 +00:00
|
|
|
type _TransformOptions = __TransformOptions & {
|
|
|
|
env?: {[key: string]: __TransformOptions},
|
|
|
|
};
|
2017-12-20 22:18:21 +00:00
|
|
|
|
|
|
|
type Ast = {};
|
|
|
|
|
2017-06-09 20:52:06 +00:00
|
|
|
type TransformResult = {
|
2017-11-03 13:06:32 +00:00
|
|
|
ast: Ast,
|
2017-06-09 20:52:06 +00:00
|
|
|
code: ?string,
|
|
|
|
ignored: boolean,
|
2018-01-11 12:27:23 +00:00
|
|
|
map: ?_BabelSourceMap,
|
2017-06-09 20:52:06 +00:00
|
|
|
};
|
2018-01-09 11:58:54 +00:00
|
|
|
// https://github.com/babel/babel/blob/master/packages/babel-generator/src/buffer.js#L42
|
|
|
|
type GeneratorResult = {
|
|
|
|
code: string,
|
2018-01-11 12:27:23 +00:00
|
|
|
map: ?_BabelSourceMap,
|
2018-01-10 11:06:38 +00:00
|
|
|
rawMappings: ?Array<_RawMapping>,
|
2018-01-09 11:58:54 +00:00
|
|
|
};
|
2017-06-09 20:52:06 +00:00
|
|
|
type VisitFn = <State>(path: Object, state: State) => any;
|
|
|
|
|
|
|
|
declare module 'babel-core' {
|
|
|
|
declare type Plugins = _Plugins;
|
2018-01-11 12:27:23 +00:00
|
|
|
declare type BabelSourceMap = _BabelSourceMap;
|
2017-12-20 22:18:21 +00:00
|
|
|
declare type Ast = {};
|
2017-06-09 20:52:06 +00:00
|
|
|
declare type TransformOptions = _TransformOptions;
|
|
|
|
declare function transform(
|
|
|
|
code: string,
|
|
|
|
options?: _TransformOptions,
|
|
|
|
): TransformResult;
|
|
|
|
declare function traverse<State>(
|
2017-11-03 13:06:32 +00:00
|
|
|
ast: Ast,
|
2018-01-11 11:12:05 +00:00
|
|
|
visitor: {
|
|
|
|
[key: string]:
|
|
|
|
| VisitFn<State>
|
|
|
|
| {enter?: VisitFn<State>, exit?: VisitFn<State>},
|
|
|
|
},
|
2017-06-09 20:52:06 +00:00
|
|
|
scope?: ?Object,
|
|
|
|
state?: State,
|
|
|
|
parentPath?: ?Object,
|
|
|
|
): void;
|
|
|
|
declare var types: {[key: string]: Function};
|
|
|
|
declare function transformFromAst(
|
2017-11-03 13:06:32 +00:00
|
|
|
ast: Ast,
|
2017-06-09 20:52:06 +00:00
|
|
|
code?: ?string,
|
|
|
|
babelOptions?: _TransformOptions,
|
|
|
|
): TransformResult;
|
|
|
|
}
|
|
|
|
|
2018-01-10 11:06:38 +00:00
|
|
|
type _RawMapping = {
|
2017-06-09 20:52:06 +00:00
|
|
|
generated: {column: number, line: number},
|
|
|
|
name?: string,
|
|
|
|
original?: {column: number, line: number},
|
|
|
|
source?: string,
|
|
|
|
};
|
|
|
|
|
2018-01-09 11:58:54 +00:00
|
|
|
// https://github.com/babel/babel/tree/master/packages/babel-generator
|
2017-06-09 20:52:06 +00:00
|
|
|
declare module 'babel-generator' {
|
2018-01-10 11:06:38 +00:00
|
|
|
declare export type RawMapping = _RawMapping;
|
|
|
|
declare export default (
|
2017-11-03 13:06:32 +00:00
|
|
|
ast: Ast,
|
2017-06-09 20:52:06 +00:00
|
|
|
options?: GeneratorOptions,
|
2018-01-09 11:58:54 +00:00
|
|
|
code?: string | {[string]: string},
|
2018-01-11 11:12:05 +00:00
|
|
|
) => GeneratorResult
|
2017-06-09 20:52:06 +00:00
|
|
|
}
|