diff --git a/flow-typed/babel.js.flow b/flow-typed/babel.js.flow index 810c0b1c..d6bbab44 100644 --- a/flow-typed/babel.js.flow +++ b/flow-typed/babel.js.flow @@ -10,7 +10,7 @@ * @format */ -type _SourceMap = { +type _BabelSourceMap = { file?: string, mappings: string, names: Array, @@ -108,19 +108,19 @@ type TransformResult = { ast: Ast, code: ?string, ignored: boolean, - map: ?_SourceMap, + map: ?_BabelSourceMap, }; // https://github.com/babel/babel/blob/master/packages/babel-generator/src/buffer.js#L42 type GeneratorResult = { code: string, - map: ?_SourceMap, + map: ?_BabelSourceMap, rawMappings: ?Array<_RawMapping>, }; type VisitFn = (path: Object, state: State) => any; declare module 'babel-core' { declare type Plugins = _Plugins; - declare type SourceMap = _SourceMap; + declare type BabelSourceMap = _BabelSourceMap; declare type Ast = {}; declare type TransformOptions = _TransformOptions; declare function transform( diff --git a/packages/metro-source-map/src/Generator.js b/packages/metro-source-map/src/Generator.js index f08b359e..8cb571c9 100644 --- a/packages/metro-source-map/src/Generator.js +++ b/packages/metro-source-map/src/Generator.js @@ -14,7 +14,7 @@ const B64Builder = require('./B64Builder'); -import type {SourceMap as MappingsMap} from 'babel-core'; +import type {BabelSourceMap} from 'babel-core'; /** * Generates a source map from raw mappings. @@ -149,7 +149,7 @@ class Generator { /** * Return the source map as object. */ - toMap(file?: string, options: {excludeSource?: boolean}): MappingsMap { + toMap(file?: string, options: {excludeSource?: boolean}): BabelSourceMap { let content; if (options && options.excludeSource) { diff --git a/packages/metro-source-map/src/source-map.js b/packages/metro-source-map/src/source-map.js index 72fa0894..5e5ce15e 100644 --- a/packages/metro-source-map/src/source-map.js +++ b/packages/metro-source-map/src/source-map.js @@ -15,12 +15,11 @@ const Generator = require('./Generator'); const SourceMap = require('source-map'); -import type {SourceMap as MappingsMap} from 'babel-core'; +import type {BabelSourceMap} from 'babel-core'; import type {RawMapping as BabelRawMapping} from 'babel-generator'; -import type {RawMapping as CompactRawMapping} from 'source-map'; +import type {RawMapping as UnknownSourceMapMappingType} from 'source-map'; -export type {SourceMap as MappingsMap} from 'babel-core'; -export type CompactRawMappings = Array; +export type UnknownSourceMapMappingTypes = Array; export type RawMappings = Array; type GeneratedCodeMapping = [number, number]; @@ -50,8 +49,8 @@ export type IndexMap = { }; export type FBIndexMap = IndexMap & FBExtensions; -export type MetroSourceMap = IndexMap | MappingsMap; -export type FBSourceMap = FBIndexMap | (MappingsMap & FBExtensions); +export type MetroSourceMap = IndexMap | BabelSourceMap; +export type FBSourceMap = FBIndexMap | (BabelSourceMap & FBExtensions); /** * Creates a source map from modules with "raw mappings", i.e. an array of @@ -91,7 +90,7 @@ function fromRawMappings( * Transforms a standard source map object into a Raw Mappings object, to be * used across the bundler. */ -function toRawMappings(sourceMap: MappingsMap): RawMappings { +function toRawMappings(sourceMap: BabelSourceMap): RawMappings { const rawMappings = []; new SourceMap.SourceMapConsumer(sourceMap).eachMapping(map => { diff --git a/packages/metro/src/Bundler/index.js b/packages/metro/src/Bundler/index.js index c59f54d8..788ca39f 100644 --- a/packages/metro/src/Bundler/index.js +++ b/packages/metro/src/Bundler/index.js @@ -32,9 +32,9 @@ import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; import type {TransformCache} from '../lib/TransformCaching'; import type {Reporter} from '../lib/reporting'; import type {HasteImpl} from '../node-haste/Module'; +import type {BabelSourceMap} from 'babel-core'; import type { - CompactRawMappings, - MappingsMap, + UnknownSourceMapMappingTypes, MetroSourceMap as SourceMap, } from 'metro-source-map'; @@ -68,8 +68,8 @@ export type GetTransformOptions = ( export type PostMinifyProcess = ({ code: string, - map: ?MappingsMap, -}) => {code: string, map: ?MappingsMap}; + map: ?BabelSourceMap, +}) => {code: string, map: ?BabelSourceMap}; export type PostProcessBundleSourcemap = ({ code: Buffer | string, @@ -255,8 +255,8 @@ class Bundler { async minifyModule( path: string, code: string, - map: CompactRawMappings, - ): Promise<{code: string, map: CompactRawMappings}> { + map: UnknownSourceMapMappingTypes, + ): Promise<{code: string, map: UnknownSourceMapMappingTypes}> { const sourceMap = fromRawMappings([{code, source: code, map, path}]).toMap( undefined, {}, diff --git a/packages/metro/src/DeltaBundler/DeltaTransformer.js b/packages/metro/src/DeltaBundler/DeltaTransformer.js index 9017963b..20a4ae4d 100644 --- a/packages/metro/src/DeltaBundler/DeltaTransformer.js +++ b/packages/metro/src/DeltaBundler/DeltaTransformer.js @@ -29,7 +29,7 @@ import type DependencyGraph from '../node-haste/DependencyGraph'; import type Module from '../node-haste/Module'; import type {Options as BundleOptions, MainOptions} from './'; import type {DependencyEdges} from './traverseDependencies'; -import type {CompactRawMappings} from 'metro-source-map'; +import type {UnknownSourceMapMappingTypes} from 'metro-source-map'; export type DeltaEntryType = | 'asset' @@ -41,7 +41,7 @@ export type DeltaEntryType = export type DeltaEntry = {| +code: string, +id: number, - +map: CompactRawMappings, + +map: UnknownSourceMapMappingTypes, +name: string, +path: string, +source: string, @@ -515,7 +515,7 @@ class DeltaTransformer extends EventEmitter { ): Promise<{ +code: string, +dependencies: Array, - +map: CompactRawMappings, + +map: UnknownSourceMapMappingTypes, +source: string, }> { return await module.read( diff --git a/packages/metro/src/DeltaBundler/Serializers.js b/packages/metro/src/DeltaBundler/Serializers.js index 80149863..b3c53cd7 100644 --- a/packages/metro/src/DeltaBundler/Serializers.js +++ b/packages/metro/src/DeltaBundler/Serializers.js @@ -28,7 +28,7 @@ import type DeltaTransformer, { DeltaEntry, DeltaTransformResponse, } from './DeltaTransformer'; -import type {MappingsMap} from 'metro-source-map'; +import type {BabelSourceMap} from 'babel-core'; export type Options = BundleOptions & { deltaBundleId: ?string, @@ -86,7 +86,7 @@ async function fullSourceMap( async function fullSourceMapObject( deltaBundler: DeltaBundler, options: Options, -): Promise { +): Promise { const {modules} = await _getAllModules(deltaBundler, options); return fromRawMappings(modules).toMap(undefined, { diff --git a/packages/metro/src/JSTransformer/index.js b/packages/metro/src/JSTransformer/index.js index 75856b55..c3f03454 100644 --- a/packages/metro/src/JSTransformer/index.js +++ b/packages/metro/src/JSTransformer/index.js @@ -17,9 +17,9 @@ const {Logger} = require('metro-core'); const debug = require('debug')('Metro:JStransformer'); const Worker = require('jest-worker').default; +import type {BabelSourceMap} from 'babel-core'; import type {Options, TransformedCode} from './worker'; import type {LocalPath} from '../node-haste/lib/toLocalPath'; -import type {MappingsMap} from 'metro-source-map'; import type {ResultWithMap} from './worker/minify'; import typeof {minify as Minify, transform as Transform} from './worker'; @@ -74,7 +74,7 @@ module.exports = class Transformer { async minify( filename: string, code: string, - sourceMap: MappingsMap, + sourceMap: BabelSourceMap, ): Promise { return await this._worker.minify(filename, code, sourceMap); } diff --git a/packages/metro/src/JSTransformer/worker/constant-folding.js b/packages/metro/src/JSTransformer/worker/constant-folding.js index 46597935..834e69ca 100644 --- a/packages/metro/src/JSTransformer/worker/constant-folding.js +++ b/packages/metro/src/JSTransformer/worker/constant-folding.js @@ -14,7 +14,8 @@ const babel = require('babel-core'); -import type {Ast, SourceMap as MappingsMap} from 'babel-core'; +import type {Ast, BabelSourceMap} from 'babel-core'; + const t = babel.types; const Conditional = { @@ -76,7 +77,7 @@ function constantFolding( transformResult: { ast: Ast, code?: ?string, - map: ?MappingsMap, + map: ?BabelSourceMap, }, ) { return babel.transformFromAst(transformResult.ast, transformResult.code, { diff --git a/packages/metro/src/JSTransformer/worker/index.js b/packages/metro/src/JSTransformer/worker/index.js index dbdad3d9..b26c1350 100644 --- a/packages/metro/src/JSTransformer/worker/index.js +++ b/packages/metro/src/JSTransformer/worker/index.js @@ -27,7 +27,8 @@ const path = require('path'); const {compactMapping} = require('metro-source-map'); import type {LogEntry} from 'metro-core/src/Logger'; -import type {CompactRawMappings, MappingsMap} from 'metro-source-map'; +import type {BabelSourceMap} from 'babel-core'; +import type {UnknownSourceMapMappingTypes} from 'metro-source-map'; import type {LocalPath} from '../../node-haste/lib/toLocalPath'; import type {ResultWithMap} from './minify'; import type {Ast, Plugins as BabelPlugins} from 'babel-core'; @@ -35,7 +36,7 @@ import type {Ast, Plugins as BabelPlugins} from 'babel-core'; export type TransformedCode = { code: string, dependencies: $ReadOnlyArray, - map: CompactRawMappings, + map: UnknownSourceMapMappingTypes, }; export type TransformArgs = {| @@ -219,7 +220,7 @@ function transformCode( function minifyCode( filename: string, code: string, - sourceMap: MappingsMap, + sourceMap: BabelSourceMap, ): ResultWithMap | Promise { try { return minify.withSourceMap(code, sourceMap, filename); diff --git a/packages/metro/src/JSTransformer/worker/inline.js b/packages/metro/src/JSTransformer/worker/inline.js index f5411ac3..08408e74 100644 --- a/packages/metro/src/JSTransformer/worker/inline.js +++ b/packages/metro/src/JSTransformer/worker/inline.js @@ -16,7 +16,8 @@ const babel = require('babel-core'); const inlinePlatform = require('./inline-platform'); const invariant = require('fbjs/lib/invariant'); -import type {Ast, SourceMap as MappingsMap} from 'babel-core'; +import type {Ast} from 'babel-core'; +import type {BabelSourceMap} from 'babel-core'; const t = babel.types; const env = {name: 'env'}; @@ -104,12 +105,12 @@ const plugin = () => inlinePlugin; type AstResult = { ast: Ast, code: ?string, - map: ?MappingsMap, + map: ?BabelSourceMap, }; function inline( filename: string, - transformResult: {ast?: ?Ast, code: string, map: ?MappingsMap}, + transformResult: {ast?: ?Ast, code: string, map: ?BabelSourceMap}, options: {+dev: boolean, +platform: ?string}, ): AstResult { const code = transformResult.code; diff --git a/packages/metro/src/JSTransformer/worker/minify.js b/packages/metro/src/JSTransformer/worker/minify.js index dc7f06dc..bc2e1b1d 100644 --- a/packages/metro/src/JSTransformer/worker/minify.js +++ b/packages/metro/src/JSTransformer/worker/minify.js @@ -14,11 +14,11 @@ const uglify = require('uglify-es'); -import type {MappingsMap} from 'metro-source-map'; +import type {BabelSourceMap} from 'babel-core'; export type ResultWithMap = { code: string, - map: MappingsMap, + map: BabelSourceMap, }; function noSourceMap(code: string): string { @@ -27,17 +27,17 @@ function noSourceMap(code: string): string { function withSourceMap( code: string, - sourceMap: ?MappingsMap, + sourceMap: ?BabelSourceMap, filename: string, ): ResultWithMap { const result = minify(code, sourceMap); - const map: MappingsMap = JSON.parse(result.map); + const map: BabelSourceMap = JSON.parse(result.map); map.sources = [filename]; return {code: result.code, map}; } -function minify(inputCode: string, inputMap: ?MappingsMap) { +function minify(inputCode: string, inputMap: ?BabelSourceMap) { const result = uglify.minify(inputCode, { mangle: {toplevel: true}, output: { diff --git a/packages/metro/src/ModuleGraph/types.flow.js b/packages/metro/src/ModuleGraph/types.flow.js index 6f1ba3fd..acd1a4ba 100644 --- a/packages/metro/src/ModuleGraph/types.flow.js +++ b/packages/metro/src/ModuleGraph/types.flow.js @@ -12,12 +12,9 @@ 'use strict'; import type {Ast} from 'babel-core'; +import type {BabelSourceMap} from 'babel-core'; import type {Console} from 'console'; -import type { - FBSourceMap, - MappingsMap, - MetroSourceMap as SourceMap, -} from 'metro-source-map'; +import type {FBSourceMap, MetroSourceMap as SourceMap} from 'metro-source-map'; export type {Transformer} from '../JSTransformer/worker'; @@ -37,7 +34,7 @@ type Dependency = {| export type File = {| code: string, - map: ?MappingsMap, + map: ?BabelSourceMap, path: string, type: CodeFileTypes, |}; @@ -144,7 +141,7 @@ type ResolveOptions = { export type TransformerResult = {| ast: ?Ast, code: string, - map: ?MappingsMap, + map: ?BabelSourceMap, |}; export type TransformResultDependency = {| @@ -164,7 +161,7 @@ export type TransformResult = {| code: string, dependencies: $ReadOnlyArray, dependencyMapName?: string, - map: ?MappingsMap, + map: ?BabelSourceMap, |}; export type TransformResults = {[string]: TransformResult}; diff --git a/packages/metro/src/ModuleGraph/worker/optimize-module.js b/packages/metro/src/ModuleGraph/worker/optimize-module.js index 31adfe69..0a3283e2 100644 --- a/packages/metro/src/ModuleGraph/worker/optimize-module.js +++ b/packages/metro/src/ModuleGraph/worker/optimize-module.js @@ -23,7 +23,8 @@ const optimizeDependencies = require('./optimizeDependencies'); const sourceMap = require('source-map'); import type {TransformedSourceFile, TransformResult} from '../types.flow'; -import type {MappingsMap, MetroSourceMap as SourceMap} from 'metro-source-map'; +import type {BabelSourceMap} from 'babel-core'; +import type {MetroSourceMap as SourceMap} from 'metro-source-map'; import type {PostMinifyProcess} from '../../Bundler/index.js'; export type OptimizationOptions = {| @@ -112,7 +113,7 @@ function mergeSourceMaps( file: string, originalMap: SourceMap, secondMap: SourceMap, -): MappingsMap { +): BabelSourceMap { const merged = new sourceMap.SourceMapGenerator(); const inputMap = new sourceMap.SourceMapConsumer(originalMap); new sourceMap.SourceMapConsumer(secondMap).eachMapping(mapping => { diff --git a/packages/metro/src/lib/TransformCaching.js b/packages/metro/src/lib/TransformCaching.js index 71646162..ab349acd 100644 --- a/packages/metro/src/lib/TransformCaching.js +++ b/packages/metro/src/lib/TransformCaching.js @@ -24,7 +24,7 @@ const writeFileAtomicSync = require('write-file-atomic').sync; import type {Options as WorkerOptions} from '../JSTransformer/worker'; import type {Reporter} from './reporting'; import type {LocalPath} from '../node-haste/lib/toLocalPath'; -import type {CompactRawMappings} from 'metro-source-map'; +import type {UnknownSourceMapMappingTypes} from 'metro-source-map'; type CacheFilePaths = {transformedCode: string, metadata: string}; export type GetTransformCacheKey = (options: {}) => string; @@ -34,7 +34,7 @@ const CACHE_SUB_DIR = 'cache'; export type CachedResult = { code: string, dependencies: $ReadOnlyArray, - map: CompactRawMappings, + map: UnknownSourceMapMappingTypes, }; export type TransformCacheResult = ?CachedResult; @@ -324,7 +324,7 @@ function readMetadataFileSync( cachedResultHash: string, cachedSourceHash: string, dependencies: Array, - sourceMap: CompactRawMappings, + sourceMap: UnknownSourceMapMappingTypes, } { const metadataStr = fs.readFileSync(metadataFilePath, 'utf8'); const metadata = tryParseJSON(metadataStr); diff --git a/packages/metro/src/node-haste/Module.js b/packages/metro/src/node-haste/Module.js index d4cef73d..b4c5c3a8 100644 --- a/packages/metro/src/node-haste/Module.js +++ b/packages/metro/src/node-haste/Module.js @@ -35,12 +35,12 @@ import type {Reporter} from '../lib/reporting'; import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers'; import type ModuleCache from './ModuleCache'; import type {LocalPath} from './lib/toLocalPath'; -import type {CompactRawMappings} from 'metro-source-map'; +import type {UnknownSourceMapMappingTypes} from 'metro-source-map'; export type ReadResult = { +code: string, +dependencies: $ReadOnlyArray, - +map: CompactRawMappings, + +map: UnknownSourceMapMappingTypes, +source: string, }; diff --git a/packages/metro/src/shared/output/unbundle/util.js b/packages/metro/src/shared/output/unbundle/util.js index 09fea30b..6bf8111c 100644 --- a/packages/metro/src/shared/output/unbundle/util.js +++ b/packages/metro/src/shared/output/unbundle/util.js @@ -15,10 +15,10 @@ const invariant = require('fbjs/lib/invariant'); import type {RamModule} from '../../../DeltaBundler/Serializers'; import type {ModuleGroups, ModuleTransportLike} from '../../types.flow'; +import type {BabelSourceMap} from 'babel-core'; import type { FBIndexMap, IndexMap, - MappingsMap, MetroSourceMap as SourceMap, } from 'metro-source-map'; @@ -29,7 +29,7 @@ const countLines = (string: string) => (string.match(newline) || []).length + 1; function lineToLineSourceMap( source: string, filename: string = '', -): MappingsMap { +): BabelSourceMap { // The first line mapping in our package is the base64vlq code for zeros (A). const firstLine = 'AAAA;';