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 = {
|
2016-11-21 21:19:13 +00:00
|
|
|
file?: string,
|
2016-11-16 18:42:13 +00:00
|
|
|
mappings: string,
|
2017-04-28 19:25:44 +00:00
|
|
|
names: Array<string>,
|
|
|
|
sourceRoot?: string,
|
|
|
|
sources: Array<string>,
|
|
|
|
sourcesContent?: Array<?string>,
|
|
|
|
version: number,
|
2016-11-16 18:42:13 +00:00
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2017-01-20 18:28:23 +00:00
|
|
|
type InlinePlugin = string | {} | () => {};
|
2017-05-09 15:02:08 +00:00
|
|
|
type _Plugins = Array<string | Object | [InlinePlugin] | [InlinePlugin, mixed]>;
|
2016-11-16 18:42:13 +00:00
|
|
|
|
2016-11-11 18:08:40 +00:00
|
|
|
// based on https://babeljs.io/docs/usage/options/ -- 2016-11-11
|
2016-12-08 13:10:37 +00:00
|
|
|
type __TransformOptions = {
|
2016-11-11 18:08:40 +00:00
|
|
|
filename?: string,
|
|
|
|
filenameRelative?: string,
|
|
|
|
presets?: Array<string | Object>,
|
2017-05-09 15:02:08 +00:00
|
|
|
plugins?: _Plugins,
|
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,
|
|
|
|
};
|
|
|
|
|
2016-12-08 13:10:37 +00:00
|
|
|
type _TransformOptions =
|
|
|
|
__TransformOptions & {env?: {[key: string]: __TransformOptions}};
|
create better debuggable source maps
Summary:
Introduces a new mechanism to build source maps that allows us to use real mapping segments instead of just mapping line-by-line.
This mechanism is only used when building development bundles to improve the debugging experience in Chrome.
The new mechanism takes advantage of a new feature in babel-generator that exposes raw mapping objects. These raw mapping objects are converted to arrays with 2, 4, or 5 for the most compact representation possible.
We no longer generate a source map for the bundle that maps each line to itself in conjunction with configuring babel generator to retain lines.
Instead, we create a source map with a large mappings object produced from the mappings of each individual file in conjunction with a “carry over” – the number of preceding lines in the bundle.
The implementation makes a couple of assumptions that hold true for babel transform results, e.g. mappings being in the order of the generated code, and that a block of mappings always belongs to the same source file. In addition, the implementation avoids allocation of objects and strings at all costs. All calculations are purely numeric, and base64 vlq produces numeric ascii character codes. These are written to a preallocated buffer objects, which is turned to a string only at the end of the building process. This implementation is ~5x faster than using the source-map library.
In addition to providing development source maps that work better, we can now also produce individual high-quality source maps for production builds and combine them to an “index source map”. This approach is unfeasable for development source maps, because index source map consistently crash Chrome.
Better production source maps are useful to get precise information about source location and symbol names when symbolicating stack traces from crashes in production.
Reviewed By: jeanlauliac
Differential Revision: D4382290
fbshipit-source-id: 365a176fa142729d0a4cef43edeb81084361e54d
2017-01-12 22:21:59 +00:00
|
|
|
declare class _Ast {}
|
2016-11-16 18:42:13 +00:00
|
|
|
type TransformResult = {
|
2016-11-17 16:48:28 +00:00
|
|
|
ast: _Ast,
|
2016-11-16 18:42:13 +00:00
|
|
|
code: ?string,
|
2017-05-09 15:02:08 +00:00
|
|
|
ignored: boolean,
|
2016-11-16 18:42:13 +00:00
|
|
|
map: ?_SourceMap,
|
|
|
|
};
|
2016-11-11 18:08:40 +00:00
|
|
|
type VisitFn = <State>(path: Object, state: State) => any;
|
|
|
|
|
|
|
|
declare module 'babel-core' {
|
2017-05-09 15:02:08 +00:00
|
|
|
declare type Plugins = _Plugins;
|
2016-11-16 18:42:13 +00:00
|
|
|
declare type SourceMap = _SourceMap;
|
|
|
|
declare type Ast = _Ast;
|
2016-12-08 13:10:37 +00:00
|
|
|
declare type TransformOptions = _TransformOptions;
|
2016-11-11 18:08:40 +00:00
|
|
|
declare function transform(
|
|
|
|
code: string,
|
2016-12-08 13:10:37 +00:00
|
|
|
options?: _TransformOptions,
|
2016-11-11 18:08:40 +00:00
|
|
|
): 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,
|
2016-12-08 13:10:37 +00:00
|
|
|
babelOptions?: _TransformOptions,
|
2016-11-16 18:42:13 +00:00
|
|
|
): TransformResult;
|
2016-11-11 18:08:40 +00:00
|
|
|
}
|
|
|
|
|
create better debuggable source maps
Summary:
Introduces a new mechanism to build source maps that allows us to use real mapping segments instead of just mapping line-by-line.
This mechanism is only used when building development bundles to improve the debugging experience in Chrome.
The new mechanism takes advantage of a new feature in babel-generator that exposes raw mapping objects. These raw mapping objects are converted to arrays with 2, 4, or 5 for the most compact representation possible.
We no longer generate a source map for the bundle that maps each line to itself in conjunction with configuring babel generator to retain lines.
Instead, we create a source map with a large mappings object produced from the mappings of each individual file in conjunction with a “carry over” – the number of preceding lines in the bundle.
The implementation makes a couple of assumptions that hold true for babel transform results, e.g. mappings being in the order of the generated code, and that a block of mappings always belongs to the same source file. In addition, the implementation avoids allocation of objects and strings at all costs. All calculations are purely numeric, and base64 vlq produces numeric ascii character codes. These are written to a preallocated buffer objects, which is turned to a string only at the end of the building process. This implementation is ~5x faster than using the source-map library.
In addition to providing development source maps that work better, we can now also produce individual high-quality source maps for production builds and combine them to an “index source map”. This approach is unfeasable for development source maps, because index source map consistently crash Chrome.
Better production source maps are useful to get precise information about source location and symbol names when symbolicating stack traces from crashes in production.
Reviewed By: jeanlauliac
Differential Revision: D4382290
fbshipit-source-id: 365a176fa142729d0a4cef43edeb81084361e54d
2017-01-12 22:21:59 +00:00
|
|
|
type RawMapping = {
|
|
|
|
generated: {column: number, line: number},
|
|
|
|
name?: string,
|
|
|
|
original?: {column: number, line: number},
|
|
|
|
source?: string,
|
|
|
|
};
|
|
|
|
|
2016-11-11 18:08:40 +00:00
|
|
|
declare module 'babel-generator' {
|
create better debuggable source maps
Summary:
Introduces a new mechanism to build source maps that allows us to use real mapping segments instead of just mapping line-by-line.
This mechanism is only used when building development bundles to improve the debugging experience in Chrome.
The new mechanism takes advantage of a new feature in babel-generator that exposes raw mapping objects. These raw mapping objects are converted to arrays with 2, 4, or 5 for the most compact representation possible.
We no longer generate a source map for the bundle that maps each line to itself in conjunction with configuring babel generator to retain lines.
Instead, we create a source map with a large mappings object produced from the mappings of each individual file in conjunction with a “carry over” – the number of preceding lines in the bundle.
The implementation makes a couple of assumptions that hold true for babel transform results, e.g. mappings being in the order of the generated code, and that a block of mappings always belongs to the same source file. In addition, the implementation avoids allocation of objects and strings at all costs. All calculations are purely numeric, and base64 vlq produces numeric ascii character codes. These are written to a preallocated buffer objects, which is turned to a string only at the end of the building process. This implementation is ~5x faster than using the source-map library.
In addition to providing development source maps that work better, we can now also produce individual high-quality source maps for production builds and combine them to an “index source map”. This approach is unfeasable for development source maps, because index source map consistently crash Chrome.
Better production source maps are useful to get precise information about source location and symbol names when symbolicating stack traces from crashes in production.
Reviewed By: jeanlauliac
Differential Revision: D4382290
fbshipit-source-id: 365a176fa142729d0a4cef43edeb81084361e54d
2017-01-12 22:21:59 +00:00
|
|
|
declare type RawMapping = RawMapping;
|
2016-11-11 18:08:40 +00:00
|
|
|
declare function exports(
|
2016-11-16 18:42:13 +00:00
|
|
|
ast: _Ast,
|
2016-11-11 18:08:40 +00:00
|
|
|
options?: GeneratorOptions,
|
create better debuggable source maps
Summary:
Introduces a new mechanism to build source maps that allows us to use real mapping segments instead of just mapping line-by-line.
This mechanism is only used when building development bundles to improve the debugging experience in Chrome.
The new mechanism takes advantage of a new feature in babel-generator that exposes raw mapping objects. These raw mapping objects are converted to arrays with 2, 4, or 5 for the most compact representation possible.
We no longer generate a source map for the bundle that maps each line to itself in conjunction with configuring babel generator to retain lines.
Instead, we create a source map with a large mappings object produced from the mappings of each individual file in conjunction with a “carry over” – the number of preceding lines in the bundle.
The implementation makes a couple of assumptions that hold true for babel transform results, e.g. mappings being in the order of the generated code, and that a block of mappings always belongs to the same source file. In addition, the implementation avoids allocation of objects and strings at all costs. All calculations are purely numeric, and base64 vlq produces numeric ascii character codes. These are written to a preallocated buffer objects, which is turned to a string only at the end of the building process. This implementation is ~5x faster than using the source-map library.
In addition to providing development source maps that work better, we can now also produce individual high-quality source maps for production builds and combine them to an “index source map”. This approach is unfeasable for development source maps, because index source map consistently crash Chrome.
Better production source maps are useful to get precise information about source location and symbol names when symbolicating stack traces from crashes in production.
Reviewed By: jeanlauliac
Differential Revision: D4382290
fbshipit-source-id: 365a176fa142729d0a4cef43edeb81084361e54d
2017-01-12 22:21:59 +00:00
|
|
|
): TransformResult & {rawMappings: ?Array<RawMapping>};
|
2016-11-11 18:08:40 +00:00
|
|
|
}
|