metro/flow-typed/babel.js.flow

165 lines
4.2 KiB
Plaintext

/**
* 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.
*
* @flow
* @format
*/
type _BabelSourceMap = {
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<
| '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,
};
type InlinePlugin = string | {} | (() => {});
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,
presets?: _Plugins,
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,
};
type _TransformOptions = __TransformOptions & {
env?: {[key: string]: __TransformOptions},
};
type Ast = {};
type TransformResult = {
ast: Ast,
code: ?string,
ignored: boolean,
map: ?_BabelSourceMap,
};
// https://github.com/babel/babel/blob/master/packages/babel-generator/src/buffer.js#L42
type GeneratorResult = {
code: string,
map: ?_BabelSourceMap,
rawMappings: ?Array<_RawMapping>,
};
type VisitFn = <State>(path: Object, state: State) => any;
declare module 'babel-core' {
declare type Plugins = _Plugins;
declare type BabelSourceMap = _BabelSourceMap;
declare type Ast = {};
declare type TransformOptions = _TransformOptions;
declare function transform(
code: string,
options?: _TransformOptions,
): TransformResult;
declare function traverse<State>(
ast: Ast,
visitor: {
[key: string]:
| VisitFn<State>
| {enter?: VisitFn<State>, exit?: VisitFn<State>},
},
scope?: ?Object,
state?: State,
parentPath?: ?Object,
): void;
declare var types: {[key: string]: Function};
declare function transformFromAst(
ast: Ast,
code?: ?string,
babelOptions?: _TransformOptions,
): TransformResult;
}
type _RawMapping = {
generated: {column: number, line: number},
name?: string,
original?: {column: number, line: number},
source?: string,
};
// https://github.com/babel/babel/tree/master/packages/babel-generator
declare module 'babel-generator' {
declare export type RawMapping = _RawMapping;
declare export default (
ast: Ast,
options?: GeneratorOptions,
code?: string | {[string]: string},
) => GeneratorResult
}