diff --git a/docs/Configuration.md b/docs/Configuration.md index 8f057477f8..991f495a16 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -549,6 +549,8 @@ Type: `string` (default: `'metro-minify-terser'`) Path, or package name resolvable from `metro-transform-worker`, to the minifier that minifies the code after transformation. +The minifier is called with `{code, map, filename, reserved, config}`, where `map` is the source map of `code` and `config` is [`minifierConfig`](#minifierconfig). It returns, or resolves to, `{code, decodedMap}`, where `decodedMap` is the source map of the minified code, composed with `map`, in decoded form: `{mappings, names}`, with `mappings` as an array of segment arrays per line, as [`@jridgewell/sourcemap-codec`](https://github.com/jridgewell/sourcemaps/tree/main/packages/sourcemap-codec)'s `decode` returns them. + #### `minifierConfig` Type: `{[key: string]: mixed}` diff --git a/packages/metro-minify-terser/src/__tests__/minify-test.js b/packages/metro-minify-terser/src/__tests__/minify-test.js index af1225a37e..afa5195c86 100644 --- a/packages/metro-minify-terser/src/__tests__/minify-test.js +++ b/packages/metro-minify-terser/src/__tests__/minify-test.js @@ -90,34 +90,17 @@ describe('Minification:', () => { expect(result.code).toBe(code); }); - test('parses the source map object provided by terser and sets the sources property', async () => { - /* $FlowFixMe[incompatible-type](>=0.99.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.99 was deployed. To see the error, delete this - * comment and run Flow. */ - terser.minify.mockResolvedValue({map: JSON.stringify(map), code: ''}); - const result = await minify({...baseOptions, filename}); - expect(result.map).toEqual({...map, sources: [filename]}); - }); - - test('returns the decoded source map provided by terser, and encodes `map` only when read', async () => { - const decodedMap = {...map, mappings: [[[0, 0, 0, 0]]]}; - let encodeCount = 0; + test('returns the decoded source map provided by terser', async () => { /* $FlowFixMe[incompatible-type] The mocked `minify` result isn't typed as * Terser's. */ terser.minify.mockResolvedValue({ code: '', - decoded_map: decodedMap, - // flowlint-next-line unsafe-getters-setters:off - get map() { - encodeCount++; - return JSON.stringify(map); - }, + decoded_map: {...map, names: ['name0'], mappings: [[[0, 0, 0, 0, 0]]]}, }); const result = await minify({...baseOptions, filename}); - expect(result.decodedMap).toEqual(decodedMap); - expect(encodeCount).toBe(0); - expect(result.map).toEqual({...map, sources: [filename]}); - expect(result.map).toBe(result.map); - expect(encodeCount).toBe(1); + expect(result).toEqual({ + code: '', + decodedMap: {names: ['name0'], mappings: [[[0, 0, 0, 0, 0]]]}, + }); }); }); diff --git a/packages/metro-minify-terser/src/__tests__/terser-issue-1341-test.js b/packages/metro-minify-terser/src/__tests__/terser-issue-1341-test.js index 3ab1486065..04762c392b 100644 --- a/packages/metro-minify-terser/src/__tests__/terser-issue-1341-test.js +++ b/packages/metro-minify-terser/src/__tests__/terser-issue-1341-test.js @@ -87,8 +87,9 @@ const GLO: MinifierOptions = { test('parallel calls do not clobber each other', async () => { const [barResult, gloResult] = await Promise.all([minify(BAR), minify(GLO)]); - const barMap = barResult.map; - const gloMap = gloResult.map; + const barMap = barResult.decodedMap; + const gloMap = gloResult.decodedMap; + expect(barMap).not.toBeNull(); expect(gloMap).not.toEqual(barMap); }); diff --git a/packages/metro-minify-terser/src/minifier.js b/packages/metro-minify-terser/src/minifier.js index 5680964b32..210ed984c6 100644 --- a/packages/metro-minify-terser/src/minifier.js +++ b/packages/metro-minify-terser/src/minifier.js @@ -9,7 +9,6 @@ * @oncall react_native */ -import type {BabelDecodedMap, BasicSourceMap} from 'metro-source-map'; import type {MinifierOptions, MinifierResult} from 'metro-transform-worker'; import terser from 'terser'; @@ -18,32 +17,26 @@ export default async function minifier( options: MinifierOptions, ): Promise { const result = await minify(options); - const {getMap} = result; - - if (!options.map || getMap == null) { + if (!options.map || result.decodedMap == null) { return {code: result.code}; } - - let map: ?BasicSourceMap; - - return { - code: result.code, - // Terser encodes its map only when `result.map` is read. - // flowlint-next-line unsafe-getters-setters:off - get map(): BasicSourceMap { - if (map == null) { - map = {...JSON.parse(getMap()), sources: [options.filename]}; - } - return map; - }, - decodedMap: result.decodedMap, - }; + const {mappings, names} = result.decodedMap; + return {code: result.code, decodedMap: {mappings, names}}; } async function minify({code, map, reserved, config}: MinifierOptions): Promise<{ code: string, - getMap: ?() => string, - decodedMap: ?BabelDecodedMap, + decodedMap: ?{ + mappings: Array< + Array< + | [number] + | [number, number, number, number] + | [number, number, number, number, number], + >, + >, + names: Array, + ... + }, }> { const options = { ...config, @@ -76,7 +69,6 @@ async function minify({code, map, reserved, config}: MinifierOptions): Promise<{ return { code: result.code, - getMap: options.sourceMap ? () => result.map : null, decodedMap: result.decoded_map, }; } diff --git a/packages/metro-source-map/API.md b/packages/metro-source-map/API.md index ea21597762..8c703c7e3c 100644 --- a/packages/metro-source-map/API.md +++ b/packages/metro-source-map/API.md @@ -125,15 +125,6 @@ export interface SourceMapGenerator { toString(file?: string, options?: {excludeSource?: boolean | undefined}): string; } -// @deprecated -export function toBabelSegments(sourceMap: BasicSourceMap): Array; - -// @deprecated -export function toSegmentTuple(mapping: BabelSourceMapSegment): MetroSourceMapSegmentTuple; - -// @deprecated -export function tuplesFromBabelDecodedMap(decodedMap: BabelDecodedMap): Array; - export type VlqMap = { readonly mappings: string; readonly names: ReadonlyArray; diff --git a/packages/metro-source-map/package.json b/packages/metro-source-map/package.json index 7f72e7002b..af387e4903 100644 --- a/packages/metro-source-map/package.json +++ b/packages/metro-source-map/package.json @@ -20,6 +20,7 @@ "dependencies": { "@babel/traverse": "^7.29.0", "@babel/types": "^7.29.8", + "@jridgewell/sourcemap-codec": "^1.5.0", "flow-enums-runtime": "^0.0.6", "invariant": "^2.2.4", "metro-symbolicate": "0.87.1", diff --git a/packages/metro-source-map/src/__tests__/__snapshots__/source-map-test.js.snap b/packages/metro-source-map/src/__tests__/__snapshots__/source-map-test.js.snap deleted file mode 100644 index 83d248696a..0000000000 --- a/packages/metro-source-map/src/__tests__/__snapshots__/source-map-test.js.snap +++ /dev/null @@ -1,114 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` 1`] = ` -Array [ - Object { - "generated": Object { - "column": 2, - "line": 1, - }, - "name": null, - "source": null, - }, - Object { - "generated": Object { - "column": 4, - "line": 3, - }, - "name": "apples", - "original": Object { - "column": 6, - "line": 5, - }, - "source": "path1", - }, - Object { - "generated": Object { - "column": 8, - "line": 7, - }, - "name": null, - "original": Object { - "column": 10, - "line": 9, - }, - "source": "path1", - }, - Object { - "generated": Object { - "column": 12, - "line": 11, - }, - "name": "pears", - "original": Object { - "column": 14, - "line": 13, - }, - "source": "path1", - }, - Object { - "generated": Object { - "column": 2, - "line": 12, - }, - "name": null, - "source": null, - }, - Object { - "generated": Object { - "column": 4, - "line": 14, - }, - "name": "bananas", - "original": Object { - "column": 16, - "line": 15, - }, - "source": "path2", - }, - Object { - "generated": Object { - "column": 12, - "line": 25, - }, - "name": null, - "source": null, - }, - Object { - "generated": Object { - "column": 14, - "line": 27, - }, - "name": "bananas", - "original": Object { - "column": 16, - "line": 15, - }, - "source": "path3", - }, - Object { - "generated": Object { - "column": 18, - "line": 31, - }, - "name": null, - "original": Object { - "column": 110, - "line": 19, - }, - "source": "path3", - }, - Object { - "generated": Object { - "column": 112, - "line": 35, - }, - "name": "pears", - "original": Object { - "column": 114, - "line": 113, - }, - "source": "path3", - }, -] -`; diff --git a/packages/metro-source-map/src/__tests__/source-map-test.js b/packages/metro-source-map/src/__tests__/source-map-test.js index 130b9295c1..aa64d01962 100644 --- a/packages/metro-source-map/src/__tests__/source-map-test.js +++ b/packages/metro-source-map/src/__tests__/source-map-test.js @@ -16,6 +16,7 @@ import type { MixedSourceMap, } from '../source-map'; +import Consumer from '../Consumer'; import {greatestLowerBound} from '../Consumer/search'; import Generator from '../Generator'; import LineIndexedMappings from '../LineIndexedMappings'; @@ -23,38 +24,35 @@ import { fromRawMappings, fromRawMappingsIndexed, isVlqMap, - toBabelSegments, - toSegmentTuple, vlqMapFromBabelDecodedMap, vlqMapFromTuples, } from '../source-map'; - -describe('flattening mappings / compacting', () => { - test('flattens simple mappings', () => { - expect(toSegmentTuple({generated: {line: 12, column: 34}})).toEqual([ - 12, 34, - ]); - }); - - test('flattens mappings with a source location', () => { - expect( - toSegmentTuple({ - generated: {column: 34, line: 12}, - original: {column: 78, line: 56}, - }), - ).toEqual([12, 34, 56, 78]); +import {get0, get1} from 'ob1'; + +// Decodes a VLQ map to raw mapping tuples, the inverse of `vlqMapFromTuples`. +function decodeTuples(vlqMap: { + readonly mappings: string, + readonly names: ReadonlyArray, + ... +}): Array { + const consumer = new Consumer({ + version: 3, + sources: [''], + names: [...vlqMap.names], + mappings: vlqMap.mappings, }); - - test('flattens mappings with a source location and a symbol name', () => { - expect( - toSegmentTuple({ - generated: {column: 34, line: 12}, - name: 'arbitrary', - original: {column: 78, line: 56}, - }), - ).toEqual([12, 34, 56, 78, 'arbitrary']); + return [...consumer.generatedMappings()].map(mapping => { + const line = get1(mapping.generatedLine); + const column = get0(mapping.generatedColumn); + const {originalLine, originalColumn, name} = mapping; + if (originalLine == null || originalColumn == null) { + return [line, column]; + } + return name == null + ? [line, column, get1(originalLine), get0(originalColumn)] + : [line, column, get1(originalLine), get0(originalColumn), name]; }); -}); +} describe('build map from raw mappings', () => { test('returns a `Generator` instance', () => { @@ -118,19 +116,6 @@ describe('build map from raw mappings', () => { }); }); - describe('convert a sourcemap into raw mappings', () => { - expect( - toBabelSegments({ - mappings: - 'E;;IAIMA;;;;QAII;;;;YAIIC;E;;ICEEC;;;;;;;;;;;Y;;cCAAA;;;;kBAI8F;;;;gHA8FID', - names: ['apples', 'pears', 'bananas'], - sources: ['path1', 'path2', 'path3'], - sourcesContent: ['code1', 'code2', 'code3'], - version: 3, - }), - ).toMatchSnapshot(); - }); - test('offsets the resulting source map by the provided offset argument', () => { const input = [ { @@ -399,18 +384,7 @@ describe('fromRawMappingsIndexed', () => { }); describe('vlqMapFromTuples', () => { - // Decode via Metro's existing string->tuples path, the inverse of - // vlqMapFromTuples. - const decode = (vlqMap: { - readonly mappings: string, - readonly names: ReadonlyArray, - }) => - toBabelSegments({ - version: 3, - sources: [''], - names: [...vlqMap.names], - mappings: vlqMap.mappings, - }).map(toSegmentTuple); + const decode = decodeTuples; test('encodes tuples into a VlqMap', () => { const vlqMap = vlqMapFromTuples([ @@ -424,7 +398,7 @@ describe('vlqMapFromTuples', () => { expect(vlqMap.names).toEqual(['apples', 'pears']); }); - test('round-trips via toBabelSegments + toSegmentTuple', () => { + test('round-trips via Consumer', () => { const tuples = [ [1, 2], [3, 4, 5, 6, 'apples'], @@ -498,7 +472,7 @@ describe('vlqMapFromBabelDecodedMap', () => { }); describe('LineIndexedMappings', () => { - // Reference lookup: decode to tuples via toBabelSegments + toSegmentTuple, + // Reference lookup: decode to tuples via Consumer, // then greatestLowerBound over (generatedLine, generatedColumn), returning the // original position only when the matched segment is on the target line and // carries source info. @@ -562,12 +536,7 @@ describe('LineIndexedMappings', () => { const tuples = cases[name]; const vlqMap = vlqMapFromTuples(tuples); // The exact tuples the old path would have produced from this VLQ map. - const reference = toBabelSegments({ - version: 3, - sources: [''], - names: [...vlqMap.names], - mappings: vlqMap.mappings, - }).map(toSegmentTuple); + const reference = decodeTuples(vlqMap); const decoded = new LineIndexedMappings(vlqMap.mappings); diff --git a/packages/metro-source-map/src/source-map.js b/packages/metro-source-map/src/source-map.js index 19a354df50..0141fa6ade 100644 --- a/packages/metro-source-map/src/source-map.js +++ b/packages/metro-source-map/src/source-map.js @@ -21,9 +21,8 @@ import { generateFunctionMap, } from './generateFunctionMap'; import Generator from './Generator'; +import {decode as decodeMappings} from '@jridgewell/sourcemap-codec'; import nullthrows from 'nullthrows'; -// $FlowFixMe[untyped-import] - source-map -import SourceMap from 'source-map'; export type {IConsumer}; @@ -121,15 +120,6 @@ export type IndexMap = { export type MixedSourceMap = IndexMap | BasicSourceMap; -type SourceMapConsumerMapping = { - generatedLine: number, - generatedColumn: number, - originalLine: ?number, - originalColumn: ?number, - source: ?string, - name: ?string, -}; - export type RawMappingsModule = { readonly map: ?ReadonlyArray | VlqMap, readonly functionMap: ?FBSourceFunctionMap, @@ -344,79 +334,9 @@ function toIndexMapSection(module: RawMappingsModule): BasicSourceMap { } /** - * Transforms a standard source map object into a Raw Mappings object, to be - * used across the bundler. - * - * @deprecated Unused by Metro, and will be removed. `Consumer`'s - * `generatedMappings()` decodes a source map. - */ -function toBabelSegments( - sourceMap: BasicSourceMap, -): Array { - const rawMappings: Array = []; - - new SourceMap.SourceMapConsumer(sourceMap).eachMapping( - (map: SourceMapConsumerMapping) => { - rawMappings.push( - map.originalLine == null || map.originalColumn == null - ? { - generated: { - line: map.generatedLine, - column: map.generatedColumn, - }, - source: map.source, - name: map.name, - } - : { - generated: { - line: map.generatedLine, - column: map.generatedColumn, - }, - original: { - line: map.originalLine, - column: map.originalColumn, - }, - source: map.source, - name: map.name, - }, - ); - }, - ); - - return rawMappings; -} - -/** - * @deprecated Unused by Metro, and will be removed. - */ -function toSegmentTuple( - mapping: BabelSourceMapSegment, -): MetroSourceMapSegmentTuple { - const {column, line} = mapping.generated; - const {name, original} = mapping; - - if (original == null) { - return [line, column]; - } - - if (typeof name !== 'string') { - return [line, column, original.line, original.column]; - } - - return [line, column, original.line, original.column, name]; -} - -/** - * Converts a Babel/gen-mapping "decoded" source map (`result.decodedMap` from - * `@babel/generator`) into raw mapping tuples, byte-identical to - * `result.rawMappings.map(toSegmentTuple)`. - * - * Preferred over `result.rawMappings` because `decodedMap` is computed eagerly - * during generation, whereas accessing `rawMappings` triggers a second decode - * (`allMappings`) that allocates ~4-5 objects per segment. No terminating - * mapping is appended (callers that need one use `countLinesAndTerminateMap`). - * - * @deprecated Unused by Metro, and will be removed. + * Converts a decoded source map (such as `result.decodedMap` from + * `@babel/generator`) into raw mapping tuples. No terminating mapping is + * appended. */ function tuplesFromBabelDecodedMap( decodedMap: BabelDecodedMap, @@ -505,22 +425,19 @@ const countLines = (string: string): number => /** * Decodes a compact VLQ map back into raw mapping tuples — the inverse of - * `vlqMapFromTuples`, reusing Metro's existing source-map consumer. + * `vlqMapFromTuples`. */ function decodeVlqMap(vlqMap: VlqMap): Array { - return toBabelSegments({ - version: 3, - sources: [''], - names: [...vlqMap.names], - mappings: vlqMap.mappings, - }).map(toSegmentTuple); + return tuplesFromBabelDecodedMap({ + mappings: decodeMappings(vlqMap.mappings), + names: vlqMap.names, + }); } /** * Encodes raw mapping tuples into a compact VLQ `mappings` string + `names` - * table. Decode the inverse via `decodeVlqMap` (or `toBabelSegments` + - * `toSegmentTuple`). Storing maps in this form uses far less memory than the - * equivalent decoded tuple arrays. + * table. Decode the inverse via `decodeVlqMap`. Storing maps in this form uses + * far less memory than the equivalent decoded tuple arrays. */ function vlqMapFromTuples( mappings: ReadonlyArray, @@ -619,9 +536,6 @@ export { functionMapBabelPlugin, isVlqMap, normalizeSourcePath, - toBabelSegments, - toSegmentTuple, - tuplesFromBabelDecodedMap, vlqMapFromBabelDecodedMap, vlqMapFromTuples, }; diff --git a/packages/metro-transform-worker/API.md b/packages/metro-transform-worker/API.md index 5406a8bc66..6327c81dd0 100644 --- a/packages/metro-transform-worker/API.md +++ b/packages/metro-transform-worker/API.md @@ -74,7 +74,6 @@ export type MinifierOptions = { export type MinifierResult = { code: string; - map?: BasicSourceMap | undefined; decodedMap?: null | undefined | BabelDecodedMap; }; diff --git a/packages/metro-transform-worker/package.json b/packages/metro-transform-worker/package.json index 8d164771fc..f38fb8e14f 100644 --- a/packages/metro-transform-worker/package.json +++ b/packages/metro-transform-worker/package.json @@ -23,7 +23,6 @@ "@babel/generator": "^7.29.1", "@babel/parser": "^7.29.9", "@babel/types": "^7.29.8", - "@jridgewell/sourcemap-codec": "^1.5.0", "flow-enums-runtime": "^0.0.6", "metro": "0.87.1", "metro-babel-transformer": "0.87.1", @@ -35,6 +34,7 @@ "nullthrows": "^1.1.1" }, "devDependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0", "@react-native/metro-babel-transformer": "0.78.0", "metro-memory-fs": "*" }, diff --git a/packages/metro-transform-worker/src/__tests__/index-test.js b/packages/metro-transform-worker/src/__tests__/index-test.js index 54b33997ec..bd8cf1b300 100644 --- a/packages/metro-transform-worker/src/__tests__/index-test.js +++ b/packages/metro-transform-worker/src/__tests__/index-test.js @@ -13,13 +13,19 @@ jest .mock('../utils/getMinifier', () => { + const {decode} = jest.requireActual( + '@jridgewell/sourcemap-codec', + ); const minifier = jest.fn(({code, map, config}) => { const trimmed = config.output.comments ? code : code.replace('/*#__PURE__*/', ''); return { code: trimmed.replace('arbitrary(code)', 'minified(code)'), - map, + decodedMap: + map == null + ? null + : {mappings: decode(map.mappings), names: map.names}, }; }); return () => minifier; @@ -33,6 +39,7 @@ jest import type {JsTransformerConfig, JsTransformOptions} from '../index'; import typeof * as TransformerType from '../index'; +import typeof * as MockSourcemapCodec from '@jridgewell/sourcemap-codec'; import typeof FSType from 'node:fs'; const {vlqMapFromBabelDecodedMap} = require('metro-source-map'); @@ -459,18 +466,11 @@ test('emits a compact VlqMap for both the non-minified and minified paths', asyn } }); -test("uses the minifier's decoded map, if it has one, without reading `map`", async () => { +test("encodes the minifier's decoded map as the module's map", async () => { const decodedMap = {mappings: [[[0, 0, 0, 0, 0]]], names: ['arbitrary']}; jest .requireMock('../utils/getMinifier')() - .mockImplementationOnce(() => ({ - code: 'minified(code);', - decodedMap, - // flowlint-next-line unsafe-getters-setters:off - get map() { - throw new Error('Expected the decoded map to be used'); - }, - })); + .mockImplementationOnce(() => ({code: 'minified(code);', decodedMap})); const result = await Transformer.transform( baseConfig, diff --git a/packages/metro-transform-worker/src/__tests__/tuplesFromBabelDecodedMap-test.js b/packages/metro-transform-worker/src/__tests__/tuplesFromBabelDecodedMap-test.js deleted file mode 100644 index eae81bf8a2..0000000000 --- a/packages/metro-transform-worker/src/__tests__/tuplesFromBabelDecodedMap-test.js +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - * @oncall react_native - */ - -'use strict'; - -import generate from '@babel/generator'; -import * as babylon from '@babel/parser'; -import {toSegmentTuple, tuplesFromBabelDecodedMap} from 'metro-source-map'; - -// The transform worker derives source-map tuples from Babel's eagerly-computed -// `result.decodedMap` instead of triggering the more expensive `rawMappings` -// (`allMappings`) decode. This must be byte-identical to the previous -// `result.rawMappings.map(toSegmentTuple)`. -const SAMPLES = [ - `function foo(aaa, bbb) { - const ccc = aaa + bbb; - return ccc * 2; -} -class Bar extends Foo { - method(xxx) { - return this.value + xxx; - } -} -export default function entry(items) { - const obj = {a: 1, b: 2, c: [1, 2, 3]}; - return items.map(x => x.value).filter(Boolean); -} -`, - `const x = require('foo');\nmodule.exports = (a, b) => { let s = 0; for (let i = 0; i < a.length; i++) { s += a[i] * b; } return s; };\n`, - `// header\nconst y = 1;\n\n\nfunction z() { return y; }\n`, - `const w = 42; const v = w + 1; export {w, v};`, - `1 + 1;\n`, -]; - -describe('tuplesFromBabelDecodedMap', () => { - test.each(SAMPLES.map((code, i) => [i, code]))( - 'is byte-identical to rawMappings.map(toSegmentTuple) [sample %i]', - (_i, code) => { - const ast = babylon.parse(code, {sourceType: 'unambiguous'}); - const result = generate( - ast, - {sourceMaps: true, sourceFileName: 'file.js'}, - code, - ); - const fromRaw = (result.rawMappings ?? []).map(toSegmentTuple); - const fromDecoded = tuplesFromBabelDecodedMap( - nullthrowsLocal(result.decodedMap), - ); - expect(fromDecoded).toEqual(fromRaw); - expect(fromDecoded.length).toBeGreaterThan(0); - }, - ); -}); - -function nullthrowsLocal(x: ?T): T { - if (x == null) { - throw new Error('Expected decodedMap to be present'); - } - return x; -} diff --git a/packages/metro-transform-worker/src/index.js b/packages/metro-transform-worker/src/index.js index a8710d9079..30fe76c9e1 100644 --- a/packages/metro-transform-worker/src/index.js +++ b/packages/metro-transform-worker/src/index.js @@ -42,8 +42,6 @@ import {transformFromAstSync} from '@babel/core'; import generate from '@babel/generator'; import * as babylon from '@babel/parser'; import * as types from '@babel/types'; -// $FlowFixMe[cannot-resolve-module] - No typings at Meta (OSS uses a libdef) -import {decode as decodeMappings} from '@jridgewell/sourcemap-codec'; import {stableHash} from 'metro-cache'; import {getCacheKey as metroGetCacheKey} from 'metro-cache-key'; import { @@ -77,11 +75,6 @@ export type MinifierOptions = { export type MinifierResult = { code: string, - /** - * @deprecated Return `decodedMap` instead. Only read if `decodedMap` is - * missing, and will be removed. - */ - map?: BasicSourceMap, // The minified code's source map, decoded, composed with the input `map`. decodedMap?: ?BabelDecodedMap, ... @@ -234,7 +227,7 @@ const minifyCode = async ( code: minified.code, lineCount, map: vlqMapFromBabelDecodedMap( - getDecodedMap(minified) ?? {mappings: [], names: []}, + minified.decodedMap ?? {mappings: [], names: []}, [lineCount, lastLineColumn], ), }; @@ -249,18 +242,6 @@ const minifyCode = async ( } }; -// A minifier may return its map already decoded, which saves decoding it here. -function getDecodedMap(minified: MinifierResult): ?BabelDecodedMap { - if (minified.decodedMap != null) { - return minified.decodedMap; - } - const {map} = minified; - if (map != null) { - return {mappings: decodeMappings(map.mappings), names: map.names}; - } - return null; -} - const disabledDependencyTransformer: DependencyTransformer = { transformIllegalDynamicRequire: () => void 0, transformImportCall: () => void 0,