metro-source-map 0.83.4 → 0.83.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro-source-map",
3
- "version": "0.83.4",
3
+ "version": "0.83.5",
4
4
  "description": "🚇 Source map generator for Metro.",
5
5
  "main": "src/source-map.js",
6
6
  "exports": {
@@ -10,7 +10,8 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git@github.com:facebook/metro.git"
13
+ "url": "git+https://github.com/facebook/metro.git",
14
+ "directory": "packages/metro-source-map"
14
15
  },
15
16
  "scripts": {
16
17
  "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
@@ -21,9 +22,9 @@
21
22
  "@babel/types": "^7.29.0",
22
23
  "flow-enums-runtime": "^0.0.6",
23
24
  "invariant": "^2.2.4",
24
- "metro-symbolicate": "0.83.4",
25
+ "metro-symbolicate": "0.83.5",
25
26
  "nullthrows": "^1.1.1",
26
- "ob1": "0.83.4",
27
+ "ob1": "0.83.5",
27
28
  "source-map": "^0.5.6",
28
29
  "vlq": "^1.0.0"
29
30
  },
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ /**
12
+ * Efficient builder for base64 VLQ mappings strings.
13
+ *
14
+ * This class uses a buffer that is preallocated with one megabyte and is
15
+ * reallocated dynamically as needed, doubling its size.
16
+ *
17
+ * Encoding never creates any complex value types (strings, objects), and only
18
+ * writes character values to the buffer.
19
+ *
20
+ * For details about source map terminology and specification, check
21
+ * https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
22
+ */
23
+ declare class B64Builder {
24
+ buffer: Buffer;
25
+ pos: number;
26
+ hasSegment: boolean;
27
+ constructor();
28
+ /**
29
+ * Adds `n` markers for generated lines to the mappings.
30
+ */
31
+ markLines(n: number): this;
32
+ /**
33
+ * Starts a segment at the specified column offset in the current line.
34
+ */
35
+ startSegment(column: number): this;
36
+ /**
37
+ * Appends a single number to the mappings.
38
+ */
39
+ append(value: number): this;
40
+ /**
41
+ * Returns the string representation of the mappings.
42
+ */
43
+ toString(): string;
44
+ _writeByte(byte: number): void;
45
+ _realloc(): void;
46
+ }
47
+ export default B64Builder;
package/src/B64Builder.js CHANGED
@@ -6,11 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _encode = _interopRequireDefault(require("./encode"));
8
8
  function _interopRequireDefault(e) {
9
- return e && e.__esModule
10
- ? e
11
- : {
12
- default: e,
13
- };
9
+ return e && e.__esModule ? e : { default: e };
14
10
  }
15
11
  const MAX_SEGMENT_LENGTH = 7;
16
12
  const ONE_MEG = 1024 * 1024;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {IndexMap, IndexMapSection, MixedSourceMap} from './source-map';
12
+ /**
13
+ * Builds a source-mapped bundle by concatenating strings and their
14
+ * corresponding source maps (if any).
15
+ *
16
+ * Usage:
17
+ *
18
+ * const builder = new BundleBuilder('bundle.js');
19
+ * builder
20
+ * .append('foo\n', fooMap)
21
+ * .append('bar\n')
22
+ * // ...
23
+ * const code = builder.getCode();
24
+ * const map = builder.getMap();
25
+ */
26
+ export declare class BundleBuilder {
27
+ _file: string;
28
+ _sections: Array<IndexMapSection>;
29
+ _line: number;
30
+ _column: number;
31
+ _code: string;
32
+ _afterMappedContent: boolean;
33
+ constructor(file: string);
34
+ _pushMapSection(map: MixedSourceMap): void;
35
+ _endMappedContent(): void;
36
+ append(code: string, map: null | undefined | MixedSourceMap): this;
37
+ getMap(): MixedSourceMap;
38
+ getCode(): string;
39
+ }
40
+ export declare function createIndexMap(
41
+ file: string,
42
+ sections: Array<IndexMapSection>,
43
+ ): IndexMap;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {
12
+ GeneratedPositionLookup,
13
+ IConsumer,
14
+ IterationOrder,
15
+ Mapping,
16
+ SourcePosition,
17
+ } from './types';
18
+
19
+ declare class AbstractConsumer implements IConsumer {
20
+ _sourceMap: {readonly file?: string};
21
+ constructor(sourceMap: {readonly file?: string});
22
+ originalPositionFor(
23
+ generatedPosition: GeneratedPositionLookup,
24
+ ): SourcePosition;
25
+ generatedMappings(): Iterable<Mapping>;
26
+ eachMapping(
27
+ callback: (mapping: Mapping) => unknown,
28
+ context?: unknown,
29
+ order?: IterationOrder,
30
+ ): void;
31
+ get file(): null | undefined | string;
32
+ sourceContentFor(
33
+ source: string,
34
+ nullOnMissing: true,
35
+ ): null | undefined | string;
36
+ }
37
+ export default AbstractConsumer;
@@ -7,11 +7,7 @@ exports.default = void 0;
7
7
  var _constants = require("./constants");
8
8
  var _invariant = _interopRequireDefault(require("invariant"));
9
9
  function _interopRequireDefault(e) {
10
- return e && e.__esModule
11
- ? e
12
- : {
13
- default: e,
14
- };
10
+ return e && e.__esModule ? e : { default: e };
15
11
  }
16
12
  class AbstractConsumer {
17
13
  constructor(sourceMap) {
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {MixedSourceMap} from '../source-map';
12
+ import type {LookupBias} from './constants.js';
13
+ import type {
14
+ GeneratedPositionLookup,
15
+ IConsumer,
16
+ IterationOrder,
17
+ Mapping,
18
+ SourcePosition,
19
+ } from './types';
20
+ /**
21
+ * A source map consumer that supports both "basic" and "indexed" source maps.
22
+ * Uses `MappingsConsumer` and `SectionsConsumer` under the hood (via
23
+ * `createConsumer`).
24
+ */
25
+ declare class DelegatingConsumer implements IConsumer {
26
+ static readonly GENERATED_ORDER: IterationOrder;
27
+ static readonly ORIGINAL_ORDER: IterationOrder;
28
+ static readonly GREATEST_LOWER_BOUND: LookupBias;
29
+ static readonly LEAST_UPPER_BOUND: LookupBias;
30
+ _rootConsumer: IConsumer;
31
+ constructor(sourceMap: MixedSourceMap);
32
+ originalPositionFor(
33
+ generatedPosition: GeneratedPositionLookup,
34
+ ): SourcePosition;
35
+ generatedMappings(): Iterable<Mapping>;
36
+ eachMapping(
37
+ callback: (mapping: Mapping) => unknown,
38
+ context?: unknown,
39
+ order?: IterationOrder,
40
+ ): void;
41
+ get file(): null | undefined | string;
42
+ sourceContentFor(
43
+ source: string,
44
+ nullOnMissing: true,
45
+ ): null | undefined | string;
46
+ }
47
+ export default DelegatingConsumer;
@@ -7,11 +7,7 @@ exports.default = void 0;
7
7
  var _constants = require("./constants");
8
8
  var _createConsumer = _interopRequireDefault(require("./createConsumer"));
9
9
  function _interopRequireDefault(e) {
10
- return e && e.__esModule
11
- ? e
12
- : {
13
- default: e,
14
- };
10
+ return e && e.__esModule ? e : { default: e };
15
11
  }
16
12
  class DelegatingConsumer {
17
13
  static GENERATED_ORDER = _constants.GENERATED_ORDER;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {BasicSourceMap} from '../source-map';
12
+ import type {
13
+ GeneratedPositionLookup,
14
+ IConsumer,
15
+ Mapping,
16
+ SourcePosition,
17
+ } from './types';
18
+ import type {Number0} from 'ob1';
19
+
20
+ import AbstractConsumer from './AbstractConsumer';
21
+ /**
22
+ * A source map consumer that supports "basic" source maps (that have a
23
+ * `mappings` field and no sections).
24
+ */
25
+ declare class MappingsConsumer extends AbstractConsumer implements IConsumer {
26
+ _sourceMap: BasicSourceMap;
27
+ _decodedMappings: null | undefined | ReadonlyArray<Mapping>;
28
+ _normalizedSources: null | undefined | ReadonlyArray<string>;
29
+ constructor(sourceMap: BasicSourceMap);
30
+ originalPositionFor(
31
+ generatedPosition: GeneratedPositionLookup,
32
+ ): SourcePosition;
33
+ _decodeMappings(): Generator<Mapping, void, void>;
34
+ _normalizeAndCacheSources(): ReadonlyArray<string>;
35
+ _decodeAndCacheMappings(): ReadonlyArray<Mapping>;
36
+ generatedMappings(): Iterable<Mapping>;
37
+ _indexOfSource(source: string): null | undefined | Number0;
38
+ sourceContentFor(
39
+ source: string,
40
+ nullOnMissing: true,
41
+ ): null | undefined | string;
42
+ }
43
+ export default MappingsConsumer;
@@ -14,11 +14,7 @@ var _invariant = _interopRequireDefault(require("invariant"));
14
14
  var _ob = require("ob1");
15
15
  var _vlq = require("vlq");
16
16
  function _interopRequireDefault(e) {
17
- return e && e.__esModule
18
- ? e
19
- : {
20
- default: e,
21
- };
17
+ return e && e.__esModule ? e : { default: e };
22
18
  }
23
19
  class MappingsConsumer extends _AbstractConsumer.default {
24
20
  constructor(sourceMap) {
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {IndexMap} from '../source-map';
12
+ import type {
13
+ GeneratedOffset,
14
+ GeneratedPositionLookup,
15
+ IConsumer,
16
+ Mapping,
17
+ SourcePosition,
18
+ } from './types';
19
+
20
+ import AbstractConsumer from './AbstractConsumer';
21
+ /**
22
+ * A source map consumer that supports "indexed" source maps (that have a
23
+ * `sections` field and no top-level mappings).
24
+ */
25
+ declare class SectionsConsumer extends AbstractConsumer implements IConsumer {
26
+ _consumers: ReadonlyArray<[GeneratedOffset, IConsumer]>;
27
+ constructor(sourceMap: IndexMap);
28
+ originalPositionFor(
29
+ generatedPosition: GeneratedPositionLookup,
30
+ ): SourcePosition;
31
+ generatedMappings(): Iterable<Mapping>;
32
+ _consumerForPosition(
33
+ generatedPosition: GeneratedPositionLookup,
34
+ ): null | undefined | [GeneratedOffset, IConsumer];
35
+ sourceContentFor(
36
+ source: string,
37
+ nullOnMissing: true,
38
+ ): null | undefined | string;
39
+ }
40
+ export default SectionsConsumer;
@@ -11,11 +11,7 @@ var _positionMath = require("./positionMath");
11
11
  var _search = require("./search");
12
12
  var _ob = require("ob1");
13
13
  function _interopRequireDefault(e) {
14
- return e && e.__esModule
15
- ? e
16
- : {
17
- default: e,
18
- };
14
+ return e && e.__esModule ? e : { default: e };
19
15
  }
20
16
  class SectionsConsumer extends _AbstractConsumer.default {
21
17
  constructor(sourceMap) {
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {Number0, Number1} from 'ob1';
12
+
13
+ declare const FIRST_COLUMN: Number0;
14
+ declare const FIRST_LINE: Number1;
15
+ export declare type IterationOrder = symbol & {__IterationOrder__: string};
16
+ declare const GENERATED_ORDER: IterationOrder;
17
+ declare const ORIGINAL_ORDER: IterationOrder;
18
+ export declare type LookupBias = symbol & {__LookupBias__: string};
19
+ declare const GREATEST_LOWER_BOUND: LookupBias;
20
+ declare const LEAST_UPPER_BOUND: LookupBias;
21
+ declare const EMPTY_POSITION: Readonly<{
22
+ source: null;
23
+ name: null;
24
+ line: null;
25
+ column: null;
26
+ }>;
27
+ declare function iterationOrderToString(x: IterationOrder): string;
28
+ declare function lookupBiasToString(x: LookupBias): string;
29
+ export {
30
+ FIRST_COLUMN,
31
+ FIRST_LINE,
32
+ GENERATED_ORDER,
33
+ ORIGINAL_ORDER,
34
+ GREATEST_LOWER_BOUND,
35
+ LEAST_UPPER_BOUND,
36
+ EMPTY_POSITION,
37
+ iterationOrderToString,
38
+ lookupBiasToString,
39
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {MixedSourceMap} from '../source-map';
12
+ import type {IConsumer} from './types';
13
+
14
+ declare function createConsumer(sourceMap: MixedSourceMap): IConsumer;
15
+ export default createConsumer;
@@ -8,11 +8,7 @@ var _MappingsConsumer = _interopRequireDefault(require("./MappingsConsumer"));
8
8
  var _SectionsConsumer = _interopRequireDefault(require("./SectionsConsumer"));
9
9
  var _invariant = _interopRequireDefault(require("invariant"));
10
10
  function _interopRequireDefault(e) {
11
- return e && e.__esModule
12
- ? e
13
- : {
14
- default: e,
15
- };
11
+ return e && e.__esModule ? e : { default: e };
16
12
  }
17
13
  function createConsumer(sourceMap) {
18
14
  (0, _invariant.default)(
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import DelegatingConsumer from './DelegatingConsumer';
12
+
13
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: typeof DelegatingConsumer;
14
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
15
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
16
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -8,10 +8,6 @@ var _DelegatingConsumer = _interopRequireDefault(
8
8
  require("./DelegatingConsumer"),
9
9
  );
10
10
  function _interopRequireDefault(e) {
11
- return e && e.__esModule
12
- ? e
13
- : {
14
- default: e,
15
- };
11
+ return e && e.__esModule ? e : { default: e };
16
12
  }
17
13
  var _default = (exports.default = _DelegatingConsumer.default);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ declare function normalizeSourcePath(
12
+ sourceInput: string,
13
+ map: {readonly sourceRoot?: null | undefined | string},
14
+ ): string;
15
+ export default normalizeSourcePath;
@@ -6,11 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = normalizeSourcePath;
7
7
  var _util = _interopRequireDefault(require("source-map/lib/util"));
8
8
  function _interopRequireDefault(e) {
9
- return e && e.__esModule
10
- ? e
11
- : {
12
- default: e,
13
- };
9
+ return e && e.__esModule ? e : { default: e };
14
10
  }
15
11
  function normalizeSourcePath(sourceInput, map) {
16
12
  const { sourceRoot } = map;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {GeneratedOffset} from './types';
12
+ import type {Number0, Number1} from 'ob1';
13
+
14
+ export declare function shiftPositionByOffset<
15
+ T extends {
16
+ readonly line: null | undefined | Number1;
17
+ readonly column: null | undefined | Number0;
18
+ },
19
+ >(pos: T, offset: GeneratedOffset): T;
20
+ export declare function subtractOffsetFromPosition<
21
+ T extends {
22
+ readonly line: null | undefined | Number1;
23
+ readonly column: null | undefined | Number0;
24
+ },
25
+ >(pos: T, offset: GeneratedOffset): T;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ export declare function greatestLowerBound<T, U>(
12
+ elements: ReadonlyArray<T>,
13
+ target: U,
14
+ comparator: ($$PARAM_0$$: U, $$PARAM_1$$: T) => number,
15
+ ): null | undefined | number;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {IterationOrder, LookupBias} from './constants';
12
+ import type {Number0, Number1} from 'ob1';
13
+
14
+ export type {IterationOrder, LookupBias};
15
+ export type GeneratedOffset = {
16
+ readonly lines: Number0;
17
+ readonly columns: Number0;
18
+ };
19
+ export type SourcePosition = {
20
+ source: null | undefined | string;
21
+ line: null | undefined | Number1;
22
+ column: null | undefined | Number0;
23
+ name: null | undefined | string;
24
+ };
25
+ export type GeneratedPosition = {
26
+ readonly line: Number1;
27
+ readonly column: Number0;
28
+ };
29
+ export type GeneratedPositionLookup = {
30
+ readonly line: null | undefined | Number1;
31
+ readonly column: null | undefined | Number0;
32
+ readonly bias?: LookupBias;
33
+ };
34
+ export type Mapping = Readonly<{
35
+ source: null | undefined | string;
36
+ generatedLine: Number1;
37
+ generatedColumn: Number0;
38
+ originalLine: null | undefined | Number1;
39
+ originalColumn: null | undefined | Number0;
40
+ name: null | undefined | string;
41
+ }>;
42
+ export interface IConsumer {
43
+ originalPositionFor(
44
+ generatedPosition: GeneratedPositionLookup,
45
+ ): SourcePosition;
46
+ generatedMappings(): Iterable<Mapping>;
47
+ eachMapping(
48
+ callback: (mapping: Mapping) => unknown,
49
+ context?: unknown,
50
+ order?: IterationOrder,
51
+ ): void;
52
+ get file(): null | undefined | string;
53
+ sourceContentFor(
54
+ source: string,
55
+ nullOnMissing: true,
56
+ ): null | undefined | string;
57
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {
12
+ BasicSourceMap,
13
+ FBSourceFunctionMap,
14
+ FBSourceMetadata,
15
+ } from './source-map';
16
+
17
+ import B64Builder from './B64Builder';
18
+
19
+ type FileFlags = Readonly<{addToIgnoreList?: boolean}>;
20
+ /**
21
+ * Generates a source map from raw mappings.
22
+ *
23
+ * Raw mappings are a set of 2, 4, or five elements:
24
+ *
25
+ * - line and column number in the generated source
26
+ * - line and column number in the original source
27
+ * - symbol name in the original source
28
+ *
29
+ * Mappings have to be passed in the order appearance in the generated source.
30
+ */
31
+ declare class Generator {
32
+ builder: B64Builder;
33
+ last: {
34
+ generatedColumn: number;
35
+ generatedLine: number;
36
+ name: number;
37
+ source: number;
38
+ sourceColumn: number;
39
+ sourceLine: number;
40
+ };
41
+ names: IndexedSet;
42
+ source: number;
43
+ sources: Array<string>;
44
+ sourcesContent: Array<null | undefined | string>;
45
+ x_facebook_sources: Array<null | undefined | FBSourceMetadata>;
46
+ x_google_ignoreList: Array<number>;
47
+ constructor();
48
+ /**
49
+ * Mark the beginning of a new source file.
50
+ */
51
+ startFile(
52
+ file: string,
53
+ code: string,
54
+ functionMap: null | undefined | FBSourceFunctionMap,
55
+ flags?: FileFlags,
56
+ ): void;
57
+ /**
58
+ * Mark the end of the current source file
59
+ */
60
+ endFile(): void;
61
+ /**
62
+ * Adds a mapping for generated code without a corresponding source location.
63
+ */
64
+ addSimpleMapping(generatedLine: number, generatedColumn: number): void;
65
+ /**
66
+ * Adds a mapping for generated code with a corresponding source location.
67
+ */
68
+ addSourceMapping(
69
+ generatedLine: number,
70
+ generatedColumn: number,
71
+ sourceLine: number,
72
+ sourceColumn: number,
73
+ ): void;
74
+ /**
75
+ * Adds a mapping for code with a corresponding source location + symbol name.
76
+ */
77
+ addNamedSourceMapping(
78
+ generatedLine: number,
79
+ generatedColumn: number,
80
+ sourceLine: number,
81
+ sourceColumn: number,
82
+ name: string,
83
+ ): void;
84
+ /**
85
+ * Return the source map as object.
86
+ */
87
+ toMap(file?: string, options?: {excludeSource?: boolean}): BasicSourceMap;
88
+ /**
89
+ * Return the source map as string.
90
+ *
91
+ * This is ~2.5x faster than calling `JSON.stringify(generator.toMap())`
92
+ */
93
+ toString(file?: string, options?: {excludeSource?: boolean}): string;
94
+ /**
95
+ * Determine whether we need to write the `x_facebook_sources` field.
96
+ * If the metadata is all `null`s, we can omit the field entirely.
97
+ */
98
+ hasSourcesMetadata(): boolean;
99
+ }
100
+ export default Generator;
101
+ declare class IndexedSet {
102
+ map: Map<string, number>;
103
+ nextIndex: number;
104
+ constructor();
105
+ indexFor(x: string): number;
106
+ items(): Array<string>;
107
+ }
package/src/Generator.js CHANGED
@@ -6,11 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _B64Builder = _interopRequireDefault(require("./B64Builder"));
8
8
  function _interopRequireDefault(e) {
9
- return e && e.__esModule
10
- ? e
11
- : {
12
- default: e,
13
- };
9
+ return e && e.__esModule ? e : { default: e };
14
10
  }
15
11
  class Generator {
16
12
  constructor() {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {MixedSourceMap} from './source-map';
12
+
13
+ declare function composeSourceMaps(
14
+ maps: ReadonlyArray<MixedSourceMap>,
15
+ ): MixedSourceMap;
16
+ export default composeSourceMaps;
@@ -7,11 +7,7 @@ exports.default = composeSourceMaps;
7
7
  var _Consumer = _interopRequireDefault(require("./Consumer"));
8
8
  var _sourceMap = require("source-map");
9
9
  function _interopRequireDefault(e) {
10
- return e && e.__esModule
11
- ? e
12
- : {
13
- default: e,
14
- };
10
+ return e && e.__esModule ? e : { default: e };
15
11
  }
16
12
  _Consumer.default;
17
13
  function composeSourceMaps(maps) {
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Portions Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ /**
12
+ * Copyright 2011 Mozilla Foundation and contributors
13
+ * Licensed under the New BSD license. See LICENSE or:
14
+ * http://opensource.org/licenses/BSD-3-Clause
15
+ *
16
+ * Based on the Base 64 VLQ implementation in Closure Compiler:
17
+ * https://git.io/vymuA
18
+ *
19
+ * Copyright 2011 The Closure Compiler Authors. All rights reserved.
20
+ * Redistribution and use in source and binary forms, with or without
21
+ * modification, are permitted provided that the following conditions are
22
+ * met:
23
+ *
24
+ * * Redistributions of source code must retain the above copyright
25
+ * notice, this list of conditions and the following disclaimer.
26
+ * * Redistributions in binary form must reproduce the above
27
+ * copyright notice, this list of conditions and the following
28
+ * disclaimer in the documentation and/or other materials provided
29
+ * with the distribution.
30
+ * * Neither the name of Google Inc. nor the names of its
31
+ * contributors may be used to endorse or promote products derived
32
+ * from this software without specific prior written permission.
33
+ *
34
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
+ *
46
+ * @copyright
47
+ *
48
+ * Associate this with the THIRD_PARTY_LICENCE type to ensure it isn't
49
+ * stripped by flow-api-translator.
50
+ */
51
+ export type THIRD_PARTY_LICENSE = unknown;
52
+ /**
53
+ * Encodes a number to base64 VLQ format and appends it to the passed-in buffer
54
+ *
55
+ * DON'T USE COMPOUND OPERATORS (eg `>>>=`) ON `let`-DECLARED VARIABLES!
56
+ * V8 WILL DEOPTIMIZE THIS FUNCTION AND MAP CREATION WILL BE 25% SLOWER!
57
+ *
58
+ * DON'T ADD MORE COMMENTS TO THIS FUNCTION TO KEEP ITS LENGTH SHORT ENOUGH FOR
59
+ * V8 OPTIMIZATION!
60
+ */
61
+ declare function encode(
62
+ value: number,
63
+ buffer: Buffer,
64
+ position: number,
65
+ ): number;
66
+ export default encode;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {FBSourceFunctionMap} from './source-map';
12
+ import type {PluginObj} from '@babel/core';
13
+ import type {Node as BabelNode} from '@babel/types';
14
+
15
+ type Position = {line: number; column: number};
16
+ type RangeMapping = {name: string; start: Position};
17
+ export type Context = {filename?: null | undefined | string};
18
+ /**
19
+ * Generate a map of source positions to function names. The names are meant to
20
+ * describe the stack frame in an error trace and may contain more contextual
21
+ * information than just the actual name of the function.
22
+ *
23
+ * The output is encoded for use in a source map. For details about the format,
24
+ * see MappingEncoder below.
25
+ */
26
+ declare function generateFunctionMap(
27
+ ast: BabelNode,
28
+ context?: Context,
29
+ ): FBSourceFunctionMap;
30
+ /**
31
+ * Same as generateFunctionMap, but returns the raw array of mappings instead
32
+ * of encoding it for use in a source map.
33
+ *
34
+ * Lines are 1-based and columns are 0-based.
35
+ */
36
+ declare function generateFunctionMappingsArray(
37
+ ast: BabelNode,
38
+ context?: Context,
39
+ ): ReadonlyArray<RangeMapping>;
40
+ declare function functionMapBabelPlugin(): PluginObj;
41
+ export {
42
+ functionMapBabelPlugin,
43
+ generateFunctionMap,
44
+ generateFunctionMappingsArray,
45
+ };
@@ -21,10 +21,7 @@ function _interopRequireWildcard(e, t) {
21
21
  if (!t && e && e.__esModule) return e;
22
22
  var o,
23
23
  i,
24
- f = {
25
- __proto__: null,
26
- default: e,
27
- };
24
+ f = { __proto__: null, default: e };
28
25
  if (null === e || ("object" != typeof e && "function" != typeof e))
29
26
  return f;
30
27
  if ((o = t ? n : r)) {
@@ -44,11 +41,7 @@ function _interopRequireWildcard(e, t) {
44
41
  })(e, t);
45
42
  }
46
43
  function _interopRequireDefault(e) {
47
- return e && e.__esModule
48
- ? e
49
- : {
50
- default: e,
51
- };
44
+ return e && e.__esModule ? e : { default: e };
52
45
  }
53
46
  function generateFunctionMap(ast, context) {
54
47
  const encoder = new MappingEncoder();
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {IConsumer} from './Consumer/types';
12
+
13
+ import {BundleBuilder, createIndexMap} from './BundleBuilder';
14
+ import composeSourceMaps from './composeSourceMaps';
15
+ import Consumer from './Consumer';
16
+ import normalizeSourcePath from './Consumer/normalizeSourcePath';
17
+ import {
18
+ functionMapBabelPlugin,
19
+ generateFunctionMap,
20
+ } from './generateFunctionMap';
21
+ import Generator from './Generator';
22
+
23
+ export type {IConsumer};
24
+ type GeneratedCodeMapping = [number, number];
25
+ type SourceMapping = [number, number, number, number];
26
+ type SourceMappingWithName = [number, number, number, number, string];
27
+ export type MetroSourceMapSegmentTuple =
28
+ | SourceMappingWithName
29
+ | SourceMapping
30
+ | GeneratedCodeMapping;
31
+ export type HermesFunctionOffsets = {
32
+ [$$Key$$: number]: ReadonlyArray<number>;
33
+ };
34
+ export type FBSourcesArray = ReadonlyArray<null | undefined | FBSourceMetadata>;
35
+ export type FBSourceMetadata = [null | undefined | FBSourceFunctionMap];
36
+ export type FBSourceFunctionMap = {
37
+ readonly names: ReadonlyArray<string>;
38
+ readonly mappings: string;
39
+ };
40
+ export type BabelSourceMapSegment = Readonly<{
41
+ generated: Readonly<{column: number; line: number}>;
42
+ original?: Readonly<{column: number; line: number}>;
43
+ source?: null | undefined | string;
44
+ name?: null | undefined | string;
45
+ }>;
46
+ export type FBSegmentMap = {[id: string]: MixedSourceMap};
47
+ export type BasicSourceMap = {
48
+ readonly file?: string;
49
+ readonly mappings: string;
50
+ readonly names: Array<string>;
51
+ readonly sourceRoot?: string;
52
+ readonly sources: Array<string>;
53
+ readonly sourcesContent?: Array<null | undefined | string>;
54
+ readonly version: number;
55
+ readonly x_facebook_offsets?: Array<number>;
56
+ readonly x_metro_module_paths?: Array<string>;
57
+ readonly x_facebook_sources?: FBSourcesArray;
58
+ readonly x_facebook_segments?: FBSegmentMap;
59
+ readonly x_hermes_function_offsets?: HermesFunctionOffsets;
60
+ readonly x_google_ignoreList?: Array<number>;
61
+ };
62
+ export type IndexMapSection = {
63
+ map: IndexMap | BasicSourceMap;
64
+ offset: {line: number; column: number};
65
+ };
66
+ export type IndexMap = {
67
+ readonly file?: string;
68
+ readonly mappings?: void;
69
+ readonly sourcesContent?: void;
70
+ readonly sections: Array<IndexMapSection>;
71
+ readonly version: number;
72
+ readonly x_facebook_offsets?: Array<number>;
73
+ readonly x_metro_module_paths?: Array<string>;
74
+ readonly x_facebook_sources?: void;
75
+ readonly x_facebook_segments?: FBSegmentMap;
76
+ readonly x_hermes_function_offsets?: HermesFunctionOffsets;
77
+ readonly x_google_ignoreList?: void;
78
+ };
79
+ export type MixedSourceMap = IndexMap | BasicSourceMap;
80
+ /**
81
+ * Creates a source map from modules with "raw mappings", i.e. an array of
82
+ * tuples with either 2, 4, or 5 elements:
83
+ * generated line, generated column, source line, source line, symbol name.
84
+ * Accepts an `offsetLines` argument in case modules' code is to be offset in
85
+ * the resulting bundle, e.g. by some prefix code.
86
+ */
87
+ declare function fromRawMappings(
88
+ modules: ReadonlyArray<{
89
+ readonly map: null | undefined | ReadonlyArray<MetroSourceMapSegmentTuple>;
90
+ readonly functionMap: null | undefined | FBSourceFunctionMap;
91
+ readonly path: string;
92
+ readonly source: string;
93
+ readonly code: string;
94
+ readonly isIgnored: boolean;
95
+ readonly lineCount?: number;
96
+ }>,
97
+ offsetLines?: number,
98
+ ): Generator;
99
+ declare function fromRawMappingsNonBlocking(
100
+ modules: ReadonlyArray<{
101
+ readonly map: null | undefined | ReadonlyArray<MetroSourceMapSegmentTuple>;
102
+ readonly functionMap: null | undefined | FBSourceFunctionMap;
103
+ readonly path: string;
104
+ readonly source: string;
105
+ readonly code: string;
106
+ readonly isIgnored: boolean;
107
+ readonly lineCount?: number;
108
+ }>,
109
+ offsetLines?: number,
110
+ ): Promise<Generator>;
111
+ /**
112
+ * Transforms a standard source map object into a Raw Mappings object, to be
113
+ * used across the bundler.
114
+ */
115
+ declare function toBabelSegments(
116
+ sourceMap: BasicSourceMap,
117
+ ): Array<BabelSourceMapSegment>;
118
+ declare function toSegmentTuple(
119
+ mapping: BabelSourceMapSegment,
120
+ ): MetroSourceMapSegmentTuple;
121
+ export {
122
+ BundleBuilder,
123
+ composeSourceMaps,
124
+ Consumer,
125
+ createIndexMap,
126
+ generateFunctionMap,
127
+ fromRawMappings,
128
+ fromRawMappingsNonBlocking,
129
+ functionMapBabelPlugin,
130
+ normalizeSourcePath,
131
+ toBabelSegments,
132
+ toSegmentTuple,
133
+ };
134
+ /**
135
+ * Backwards-compatibility with CommonJS consumers using interopRequireDefault.
136
+ * Do not add to this list.
137
+ *
138
+ * @deprecated Default import from 'metro-source-map' is deprecated, use named exports.
139
+ */
140
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: {
141
+ BundleBuilder: typeof BundleBuilder;
142
+ composeSourceMaps: typeof composeSourceMaps;
143
+ Consumer: typeof Consumer;
144
+ createIndexMap: typeof createIndexMap;
145
+ generateFunctionMap: typeof generateFunctionMap;
146
+ fromRawMappings: typeof fromRawMappings;
147
+ fromRawMappingsNonBlocking: typeof fromRawMappingsNonBlocking;
148
+ functionMapBabelPlugin: typeof functionMapBabelPlugin;
149
+ normalizeSourcePath: typeof normalizeSourcePath;
150
+ toBabelSegments: typeof toBabelSegments;
151
+ toSegmentTuple: typeof toSegmentTuple;
152
+ };
153
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
154
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
155
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
package/src/source-map.js CHANGED
@@ -60,11 +60,7 @@ var _generateFunctionMap = require("./generateFunctionMap");
60
60
  var _Generator = _interopRequireDefault(require("./Generator"));
61
61
  var _sourceMap = _interopRequireDefault(require("source-map"));
62
62
  function _interopRequireDefault(e) {
63
- return e && e.__esModule
64
- ? e
65
- : {
66
- default: e,
67
- };
63
+ return e && e.__esModule ? e : { default: e };
68
64
  }
69
65
  function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
70
66
  const modulesToProcess = modules.slice();