From 77401b15e0b4dcc264709d3a8c8123ea595a7bd3 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Fri, 11 Nov 2016 10:08:40 -0800 Subject: [PATCH] Add flow declarations for `babel-core` Reviewed By: zertosh Differential Revision: D4166844 fbshipit-source-id: 5ee67b6629179c195dcdeacf87121a3fcd75a738 --- flow/babel.js.flow | 103 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 flow/babel.js.flow diff --git a/flow/babel.js.flow b/flow/babel.js.flow new file mode 100644 index 000000000..ed4ae9fb7 --- /dev/null +++ b/flow/babel.js.flow @@ -0,0 +1,103 @@ +/** + * 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. + */ + +// 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, +}; + +// based on https://babeljs.io/docs/usage/options/ -- 2016-11-11 +type _TransformOptions = { + filename?: string, + filenameRelative?: string, + presets?: Array, + plugins?: Array, + parserOpts?: BabylonOptions, + generatorOpts?: GeneratorOptions, + highlightCode?: boolean, + only?: string | RegExp | Array, + ignore?: string | RegExp | Array, + 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 TransformResult = {}; +type VisitFn = (path: Object, state: State) => any; + +declare module 'babel-core' { + declare function transform( + code: string, + options?: TransformOptions, + ): TransformResult; + declare function traverse( + ast: Object, + visitor: {[key: string]: VisitFn | + {enter?: VisitFn, exit?: VisitFn}}, + scope?: ?Object, + state?: State, + parentPath?: ?Object, + ): void; + declare var types: {[key: string]: Function}; +} + +declare module 'babel-generator' { + declare function exports( + ast: Object, + options?: GeneratorOptions, + ): {ast: Object, code: string, map: Object}; +}