metro-source-map 0.80.5 → 0.80.6

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.80.5",
3
+ "version": "0.80.6",
4
4
  "description": "🚇 Source map generator for Metro.",
5
5
  "main": "src/source-map.js",
6
6
  "repository": {
@@ -15,9 +15,9 @@
15
15
  "@babel/traverse": "^7.20.0",
16
16
  "@babel/types": "^7.20.0",
17
17
  "invariant": "^2.2.4",
18
- "metro-symbolicate": "0.80.5",
18
+ "metro-symbolicate": "0.80.6",
19
19
  "nullthrows": "^1.1.1",
20
- "ob1": "0.80.5",
20
+ "ob1": "0.80.6",
21
21
  "source-map": "^0.5.6",
22
22
  "vlq": "^1.0.0"
23
23
  },
package/src/B64Builder.js CHANGED
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const encode = require("./encode");
@@ -16,29 +5,12 @@ const MAX_SEGMENT_LENGTH = 7;
16
5
  const ONE_MEG = 1024 * 1024;
17
6
  const COMMA = 0x2c;
18
7
  const SEMICOLON = 0x3b;
19
-
20
- /**
21
- * Efficient builder for base64 VLQ mappings strings.
22
- *
23
- * This class uses a buffer that is preallocated with one megabyte and is
24
- * reallocated dynamically as needed, doubling its size.
25
- *
26
- * Encoding never creates any complex value types (strings, objects), and only
27
- * writes character values to the buffer.
28
- *
29
- * For details about source map terminology and specification, check
30
- * https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
31
- */
32
8
  class B64Builder {
33
9
  constructor() {
34
10
  this.buffer = Buffer.alloc(ONE_MEG);
35
11
  this.pos = 0;
36
12
  this.hasSegment = false;
37
13
  }
38
-
39
- /**
40
- * Adds `n` markers for generated lines to the mappings.
41
- */
42
14
  markLines(n) {
43
15
  if (n < 1) {
44
16
  return this;
@@ -52,10 +24,6 @@ class B64Builder {
52
24
  }
53
25
  return this;
54
26
  }
55
-
56
- /**
57
- * Starts a segment at the specified column offset in the current line.
58
- */
59
27
  startSegment(column) {
60
28
  if (this.hasSegment) {
61
29
  this._writeByte(COMMA);
@@ -65,10 +33,6 @@ class B64Builder {
65
33
  this.append(column);
66
34
  return this;
67
35
  }
68
-
69
- /**
70
- * Appends a single number to the mappings.
71
- */
72
36
  append(value) {
73
37
  if (this.pos + MAX_SEGMENT_LENGTH >= this.buffer.length) {
74
38
  this._realloc();
@@ -76,10 +40,6 @@ class B64Builder {
76
40
  this.pos = encode(value, this.buffer, this.pos);
77
41
  return this;
78
42
  }
79
-
80
- /**
81
- * Returns the string representation of the mappings.
82
- */
83
43
  toString() {
84
44
  return this.buffer.toString("ascii", 0, this.pos);
85
45
  }
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const EMPTY_MAP = {
@@ -17,21 +6,6 @@ const EMPTY_MAP = {
17
6
  names: [],
18
7
  mappings: "A",
19
8
  };
20
-
21
- /**
22
- * Builds a source-mapped bundle by concatenating strings and their
23
- * corresponding source maps (if any).
24
- *
25
- * Usage:
26
- *
27
- * const builder = new BundleBuilder('bundle.js');
28
- * builder
29
- * .append('foo\n', fooMap)
30
- * .append('bar\n')
31
- * // ...
32
- * const code = builder.getCode();
33
- * const map = builder.getMap();
34
- */
35
9
  class BundleBuilder {
36
10
  constructor(file) {
37
11
  this._file = file;
@@ -1,20 +1,7 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const { GENERATED_ORDER, iterationOrderToString } = require("./constants");
15
4
  const invariant = require("invariant");
16
-
17
- // Implementation details shared between MappingsConsumer and SectionsConsumer
18
5
  class AbstractConsumer {
19
6
  constructor(sourceMap) {
20
7
  this._sourceMap = sourceMap;
@@ -34,8 +21,6 @@ class AbstractConsumer {
34
21
  callback.call(context, mapping);
35
22
  }
36
23
  }
37
-
38
- // flowlint-next-line unsafe-getters-setters:off
39
24
  get file() {
40
25
  return this._sourceMap.file;
41
26
  }
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const {
@@ -18,18 +7,11 @@ const {
18
7
  ORIGINAL_ORDER,
19
8
  } = require("./constants");
20
9
  const createConsumer = require("./createConsumer");
21
-
22
- /**
23
- * A source map consumer that supports both "basic" and "indexed" source maps.
24
- * Uses `MappingsConsumer` and `SectionsConsumer` under the hood (via
25
- * `createConsumer`).
26
- */
27
10
  class DelegatingConsumer {
28
11
  static GENERATED_ORDER = GENERATED_ORDER;
29
12
  static ORIGINAL_ORDER = ORIGINAL_ORDER;
30
13
  static GREATEST_LOWER_BOUND = GREATEST_LOWER_BOUND;
31
14
  static LEAST_UPPER_BOUND = LEAST_UPPER_BOUND;
32
- // $FlowFixMe[incompatible-return]
33
15
  constructor(sourceMap) {
34
16
  this._rootConsumer = createConsumer(sourceMap);
35
17
  return this._rootConsumer;
@@ -43,8 +25,6 @@ class DelegatingConsumer {
43
25
  eachMapping(callback, context, order) {
44
26
  return this._rootConsumer.eachMapping(callback, context, order);
45
27
  }
46
-
47
- // flowlint-next-line unsafe-getters-setters:off
48
28
  get file() {
49
29
  return this._rootConsumer.file;
50
30
  }
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const AbstractConsumer = require("./AbstractConsumer");
@@ -24,11 +13,6 @@ const { greatestLowerBound } = require("./search");
24
13
  const invariant = require("invariant");
25
14
  const { add, add0, get0, inc, sub } = require("ob1");
26
15
  const { decode: decodeVlq } = require("vlq");
27
-
28
- /**
29
- * A source map consumer that supports "basic" source maps (that have a
30
- * `mappings` field and no sections).
31
- */
32
16
  class MappingsConsumer extends AbstractConsumer {
33
17
  constructor(sourceMap) {
34
18
  super(sourceMap);
@@ -47,7 +31,6 @@ class MappingsConsumer extends AbstractConsumer {
47
31
  invariant(
48
32
  generatedPosition.bias === GREATEST_LOWER_BOUND,
49
33
  `Unimplemented lookup bias: ${lookupBiasToString(
50
- // $FlowFixMe[incompatible-call]
51
34
  generatedPosition.bias
52
35
  )}`
53
36
  );
@@ -98,7 +81,6 @@ class MappingsConsumer extends AbstractConsumer {
98
81
  case ";":
99
82
  generatedLine = inc(generatedLine);
100
83
  generatedColumn = FIRST_COLUMN;
101
- /* falls through */
102
84
  case ",":
103
85
  next = i + 1;
104
86
  continue;
@@ -106,7 +88,6 @@ class MappingsConsumer extends AbstractConsumer {
106
88
  findNext: for (next = i + 1; next < mappingsRaw.length; ++next) {
107
89
  switch (mappingsRaw[next]) {
108
90
  case ";":
109
- /* falls through */
110
91
  case ",":
111
92
  break findNext;
112
93
  }
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const AbstractConsumer = require("./AbstractConsumer");
@@ -17,11 +6,6 @@ const createConsumer = require("./createConsumer");
17
6
  const { subtractOffsetFromPosition } = require("./positionMath");
18
7
  const { greatestLowerBound } = require("./search");
19
8
  const { add, add0, get0, get1, sub, sub1 } = require("ob1");
20
-
21
- /**
22
- * A source map consumer that supports "indexed" source maps (that have a
23
- * `sections` field and no top-level mappings).
24
- */
25
9
  class SectionsConsumer extends AbstractConsumer {
26
10
  constructor(sourceMap) {
27
11
  super(sourceMap);
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const { add0, add1 } = require("ob1");
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const invariant = require("invariant");
@@ -19,8 +8,6 @@ function createConsumer(sourceMap) {
19
8
  );
20
9
  const MappingsConsumer = require("./MappingsConsumer");
21
10
  const SectionsConsumer = require("./SectionsConsumer");
22
-
23
- // eslint-disable-next-line lint/strictly-null
24
11
  if (sourceMap.mappings === undefined) {
25
12
  return new SectionsConsumer(sourceMap);
26
13
  }
@@ -1,16 +1,4 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
- // Implements an API-compatible subset of source-map's `SourceMapConsumer`.
15
3
  const DelegatingConsumer = require("./DelegatingConsumer");
16
4
  module.exports = DelegatingConsumer;
@@ -1,32 +1,11 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
- // flowlint-next-line untyped-import:off
15
3
  const util = require("source-map/lib/util");
16
-
17
- // Extracted from source-map@0.5.6's SourceMapConsumer
18
4
  function normalizeSourcePath(sourceInput, map) {
19
5
  const { sourceRoot } = map;
20
6
  let source = sourceInput;
21
7
  source = String(source);
22
- // Some source maps produce relative source paths like "./foo.js" instead of
23
- // "foo.js". Normalize these first so that future comparisons will succeed.
24
- // See bugzil.la/1090768.
25
8
  source = util.normalize(source);
26
- // Always ensure that absolute sources are internally stored relative to
27
- // the source root, if the source root is absolute. Not doing this would
28
- // be particularly problematic when the source root is a prefix of the
29
- // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
30
9
  source =
31
10
  sourceRoot != null && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
32
11
  ? util.relative(sourceRoot, source)
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const { add, add0, add1, neg } = require("ob1");
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  function greatestLowerBound(elements, target, comparator) {
@@ -1,12 +1 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
package/src/Generator.js CHANGED
@@ -1,37 +1,12 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const B64Builder = require("./B64Builder");
15
- /**
16
- * Generates a source map from raw mappings.
17
- *
18
- * Raw mappings are a set of 2, 4, or five elements:
19
- *
20
- * - line and column number in the generated source
21
- * - line and column number in the original source
22
- * - symbol name in the original source
23
- *
24
- * Mappings have to be passed in the order appearance in the generated source.
25
- */
26
4
  class Generator {
27
- // https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension
28
-
29
5
  constructor() {
30
6
  this.builder = new B64Builder();
31
7
  this.last = {
32
8
  generatedColumn: 0,
33
9
  generatedLine: 1,
34
- // lines are passed in 1-indexed
35
10
  name: 0,
36
11
  source: 0,
37
12
  sourceColumn: 0,
@@ -44,10 +19,6 @@ class Generator {
44
19
  this.x_facebook_sources = [];
45
20
  this.x_google_ignoreList = [];
46
21
  }
47
-
48
- /**
49
- * Mark the beginning of a new source file.
50
- */
51
22
  startFile(file, code, functionMap, flags) {
52
23
  const { addToIgnoreList = false } = flags ?? {};
53
24
  const sourceIndex = this.sources.push(file) - 1;
@@ -58,17 +29,9 @@ class Generator {
58
29
  this.x_google_ignoreList.push(sourceIndex);
59
30
  }
60
31
  }
61
-
62
- /**
63
- * Mark the end of the current source file
64
- */
65
32
  endFile() {
66
33
  this.source = -1;
67
34
  }
68
-
69
- /**
70
- * Adds a mapping for generated code without a corresponding source location.
71
- */
72
35
  addSimpleMapping(generatedLine, generatedColumn) {
73
36
  const last = this.last;
74
37
  if (
@@ -91,10 +54,6 @@ class Generator {
91
54
  this.builder.startSegment(generatedColumn - last.generatedColumn);
92
55
  last.generatedColumn = generatedColumn;
93
56
  }
94
-
95
- /**
96
- * Adds a mapping for generated code with a corresponding source location.
97
- */
98
57
  addSourceMapping(generatedLine, generatedColumn, sourceLine, sourceColumn) {
99
58
  this.addSimpleMapping(generatedLine, generatedColumn);
100
59
  const last = this.last;
@@ -106,10 +65,6 @@ class Generator {
106
65
  last.sourceColumn = sourceColumn;
107
66
  last.sourceLine = sourceLine;
108
67
  }
109
-
110
- /**
111
- * Adds a mapping for code with a corresponding source location + symbol name.
112
- */
113
68
  addNamedSourceMapping(
114
69
  generatedLine,
115
70
  generatedColumn,
@@ -128,10 +83,6 @@ class Generator {
128
83
  this.builder.append(nameIndex - last.name);
129
84
  last.name = nameIndex;
130
85
  }
131
-
132
- /**
133
- * Return the source map as object.
134
- */
135
86
  toMap(file, options) {
136
87
  const content =
137
88
  options && options.excludeSource === true
@@ -162,12 +113,6 @@ class Generator {
162
113
  mappings: this.builder.toString(),
163
114
  };
164
115
  }
165
-
166
- /**
167
- * Return the source map as string.
168
- *
169
- * This is ~2.5x faster than calling `JSON.stringify(generator.toMap())`
170
- */
171
116
  toString(file, options) {
172
117
  let content;
173
118
  if (options && options.excludeSource === true) {
@@ -204,11 +149,6 @@ class Generator {
204
149
  "}"
205
150
  );
206
151
  }
207
-
208
- /**
209
- * Determine whether we need to write the `x_facebook_sources` field.
210
- * If the metadata is all `null`s, we can omit the field entirely.
211
- */
212
152
  hasSourcesMetadata() {
213
153
  return this.x_facebook_sources.some(
214
154
  (metadata) => metadata != null && metadata.some((value) => value != null)
@@ -1,25 +1,9 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const Consumer = require("./Consumer");
15
4
  const { SourceMapGenerator } = require("source-map");
16
-
17
- // TODO(t67648443): Bypass the `sort-requires` rule for this file because of a dependency cycle.
18
5
  Consumer;
19
-
20
- // Originally based on https://github.com/jakobwesthoff/source-map-merger
21
6
  function composeSourceMaps(maps) {
22
- // NOTE: require() here to break dependency cycle
23
7
  const SourceMetadataMapConsumer = require("metro-symbolicate/src/SourceMetadataMapConsumer");
24
8
  const GoogleIgnoreListConsumer = require("metro-symbolicate/src/GoogleIgnoreListConsumer");
25
9
  if (maps.length < 1) {
@@ -111,7 +95,6 @@ function findOriginalPosition(consumers, generatedLine, generatedColumn) {
111
95
  };
112
96
  }
113
97
  }
114
- // $FlowFixMe[incompatible-return] `Number0`, `Number1` is incompatible with number
115
98
  return original;
116
99
  }
117
100
  module.exports = composeSourceMaps;
package/src/encode.js CHANGED
@@ -1,57 +1,5 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
- /**
13
- * Copyright 2011 Mozilla Foundation and contributors
14
- * Licensed under the New BSD license. See LICENSE or:
15
- * http://opensource.org/licenses/BSD-3-Clause
16
- *
17
- * Based on the Base 64 VLQ implementation in Closure Compiler:
18
- * https://git.io/vymuA
19
- *
20
- * Copyright 2011 The Closure Compiler Authors. All rights reserved.
21
- * Redistribution and use in source and binary forms, with or without
22
- * modification, are permitted provided that the following conditions are
23
- * met:
24
- *
25
- * * Redistributions of source code must retain the above copyright
26
- * notice, this list of conditions and the following disclaimer.
27
- * * Redistributions in binary form must reproduce the above
28
- * copyright notice, this list of conditions and the following
29
- * disclaimer in the documentation and/or other materials provided
30
- * with the distribution.
31
- * * Neither the name of Google Inc. nor the names of its
32
- * contributors may be used to endorse or promote products derived
33
- * from this software without specific prior written permission.
34
- *
35
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46
- *
47
- * @copyright
48
- */
49
-
50
- /* eslint-disable no-bitwise */
51
-
52
1
  "use strict";
53
2
 
54
- // A map of values to characters for the b64 encoding
55
3
  const CHAR_MAP = [
56
4
  0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
57
5
  0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
@@ -59,49 +7,13 @@ const CHAR_MAP = [
59
7
  0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
60
8
  0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f,
61
9
  ];
62
-
63
- // A single base 64 digit can contain 6 bits of data. For the base 64 variable
64
- // length quantities we use in the source map spec, the first bit is the sign,
65
- // the next four bits are the actual value, and the 6th bit is the
66
- // continuation bit. The continuation bit tells us whether there are more
67
- // digits in this value following this digit.
68
- //
69
- // Continuation
70
- // | Sign
71
- // | |
72
- // V V
73
- // 101011
74
-
75
10
  const VLQ_BASE_SHIFT = 5;
76
-
77
- // binary: 100000
78
11
  const VLQ_BASE = 1 << VLQ_BASE_SHIFT;
79
-
80
- // binary: 011111
81
12
  const VLQ_BASE_MASK = VLQ_BASE - 1;
82
-
83
- // binary: 100000
84
13
  const VLQ_CONTINUATION_BIT = VLQ_BASE;
85
-
86
- /**
87
- * Converts from a two-complement value to a value where the sign bit is
88
- * placed in the least significant bit. For example, as decimals:
89
- * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
90
- * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
91
- */
92
14
  function toVLQSigned(value) {
93
15
  return value < 0 ? (-value << 1) + 1 : (value << 1) + 0;
94
16
  }
95
-
96
- /**
97
- * Encodes a number to base64 VLQ format and appends it to the passed-in buffer
98
- *
99
- * DON'T USE COMPOUND OPERATORS (eg `>>>=`) ON `let`-DECLARED VARIABLES!
100
- * V8 WILL DEOPTIMIZE THIS FUNCTION AND MAP CREATION WILL BE 25% SLOWER!
101
- *
102
- * DON'T ADD MORE COMMENTS TO THIS FUNCTION TO KEEP ITS LENGTH SHORT ENOUGH FOR
103
- * V8 OPTIMIZATION!
104
- */
105
17
  function encode(value, buffer, position) {
106
18
  let vlq = toVLQSigned(value);
107
19
  let digit;
@@ -109,8 +21,6 @@ function encode(value, buffer, position) {
109
21
  digit = vlq & VLQ_BASE_MASK;
110
22
  vlq = vlq >>> VLQ_BASE_SHIFT;
111
23
  if (vlq > 0) {
112
- // There are still more digits in this value, so we must make sure the
113
- // continuation bit is marked.
114
24
  digit = digit | VLQ_CONTINUATION_BIT;
115
25
  }
116
26
  buffer[position++] = CHAR_MAP[digit];
@@ -1,14 +1,3 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  var _traverse = _interopRequireDefault(require("@babel/traverse"));
@@ -21,26 +10,11 @@ const t = require("@babel/types");
21
10
  const invariant = require("invariant");
22
11
  const nullthrows = require("nullthrows");
23
12
  const fsPath = require("path");
24
- /**
25
- * Generate a map of source positions to function names. The names are meant to
26
- * describe the stack frame in an error trace and may contain more contextual
27
- * information than just the actual name of the function.
28
- *
29
- * The output is encoded for use in a source map. For details about the format,
30
- * see MappingEncoder below.
31
- */
32
13
  function generateFunctionMap(ast, context) {
33
14
  const encoder = new MappingEncoder();
34
15
  forEachMapping(ast, context, (mapping) => encoder.push(mapping));
35
16
  return encoder.getResult();
36
17
  }
37
-
38
- /**
39
- * Same as generateFunctionMap, but returns the raw array of mappings instead
40
- * of encoding it for use in a source map.
41
- *
42
- * Lines are 1-based and columns are 0-based.
43
- */
44
18
  function generateFunctionMappingsArray(ast, context) {
45
19
  const mappings = [];
46
20
  forEachMapping(ast, context, (mapping) => {
@@ -50,9 +24,6 @@ function generateFunctionMappingsArray(ast, context) {
50
24
  }
51
25
  function functionMapBabelPlugin() {
52
26
  return {
53
- // Eagerly traverse the tree on `pre`, before any visitors have run, so
54
- // that regardless of plugin order we're dealing with the AST before any
55
- // mutations.
56
27
  visitor: {},
57
28
  pre: ({ path, metadata, opts }) => {
58
29
  const { filename } = nullthrows(opts);
@@ -67,8 +38,6 @@ function functionMapBabelPlugin() {
67
38
  path && t.isProgram(path.node),
68
39
  "path missing or not a program node"
69
40
  );
70
- // $FlowFixMe[prop-missing] checked above
71
- // $FlowFixMe[incompatible-type-arg] checked above
72
41
  const programPath = path;
73
42
  visitor.enter(programPath);
74
43
  programPath.traverse({
@@ -76,12 +45,8 @@ function functionMapBabelPlugin() {
76
45
  Class: visitor,
77
46
  });
78
47
  visitor.exit(programPath);
79
-
80
- // $FlowFixMe[prop-missing] Babel `File` is not generically typed
81
48
  const metroMetadata = metadata;
82
49
  const functionMap = encoder.getResult();
83
-
84
- // Set the result on a metadata property
85
50
  if (!metroMetadata.metro) {
86
51
  metroMetadata.metro = {
87
52
  functionMap,
@@ -101,7 +66,7 @@ function getFunctionMapVisitor(context, pushMapping) {
101
66
  let tailName = null;
102
67
  function advanceToPos(pos) {
103
68
  if (tailPos && positionGreater(pos, tailPos)) {
104
- const name = nameStack[0].name; // We always have at least Program
69
+ const name = nameStack[0].name;
105
70
  if (name !== tailName) {
106
71
  pushMapping({
107
72
  name,
@@ -149,22 +114,11 @@ function getFunctionMapVisitor(context, pushMapping) {
149
114
  },
150
115
  };
151
116
  }
152
-
153
- /**
154
- * Traverses a Babel AST and calls the supplied callback with function name
155
- * mappings, one at a time.
156
- */
157
117
  function forEachMapping(ast, context, pushMapping) {
158
118
  const visitor = getFunctionMapVisitor(context, pushMapping);
159
-
160
- // Traversing populates/pollutes the path cache (`traverse.cache.path`) with
161
- // values missing the `hub` property needed by Babel transformation, so we
162
- // save, clear, and restore the cache around our traversal.
163
- // See: https://github.com/facebook/metro/pull/854#issuecomment-1336499395
164
119
  const previousCache = _traverse.default.cache.path;
165
120
  _traverse.default.cache.clearPath();
166
121
  (0, _traverse.default)(ast, {
167
- // Our visitor doesn't care about scope
168
122
  noScope: true,
169
123
  Function: visitor,
170
124
  Program: visitor,
@@ -173,88 +127,59 @@ function forEachMapping(ast, context, pushMapping) {
173
127
  _traverse.default.cache.path = previousCache;
174
128
  }
175
129
  const ANONYMOUS_NAME = "<anonymous>";
176
-
177
- /**
178
- * Derive a contextual name for the given AST node (Function, Program, Class or
179
- * ObjectExpression).
180
- */
181
130
  function getNameForPath(path) {
182
131
  const { node, parent, parentPath } = path;
183
132
  if ((0, _types.isProgram)(node)) {
184
133
  return "<global>";
185
134
  }
186
135
  let { id } = path;
187
- // has an `id` so we don't need to infer one
188
136
  if (node.id) {
189
- // $FlowFixMe Flow error uncovered by typing Babel more strictly
190
137
  return node.id.name;
191
138
  }
192
139
  let propertyPath;
193
140
  let kind;
194
-
195
- // Find or construct an AST node that names the current node.
196
141
  if ((0, _types.isObjectMethod)(node) || (0, _types.isClassMethod)(node)) {
197
- // ({ foo() {} });
198
142
  id = node.key;
199
143
  if (node.kind !== "method" && node.kind !== "constructor") {
200
- // Store the method's kind so we can add it to the final name.
201
144
  kind = node.kind;
202
145
  }
203
- // Also store the path to the property so we can find its context
204
- // (object/class) later and add _its_ name to the result.
205
146
  propertyPath = path;
206
147
  } else if (
207
148
  (0, _types.isObjectProperty)(parent) ||
208
149
  (0, _types.isClassProperty)(parent)
209
150
  ) {
210
- // ({ foo: function() {} });
211
151
  id = parent.key;
212
- // Also store the path to the property so we can find its context
213
- // (object/class) later and add _its_ name to the result.
214
152
  propertyPath = parentPath;
215
153
  } else if ((0, _types.isVariableDeclarator)(parent)) {
216
- // let foo = function () {};
217
154
  id = parent.id;
218
155
  } else if ((0, _types.isAssignmentExpression)(parent)) {
219
- // foo = function () {};
220
156
  id = parent.left;
221
157
  } else if ((0, _types.isJSXExpressionContainer)(parent)) {
222
158
  const grandParentNode = parentPath?.parentPath?.node;
223
159
  if ((0, _types.isJSXElement)(grandParentNode)) {
224
- // <foo>{function () {}}</foo>
225
160
  const openingElement = grandParentNode.openingElement;
226
161
  id = t.jsxMemberExpression(
227
- // $FlowFixMe Flow error uncovered by typing Babel more strictly
228
162
  t.jsxMemberExpression(openingElement.name, t.jsxIdentifier("props")),
229
163
  t.jsxIdentifier("children")
230
164
  );
231
165
  } else if ((0, _types.isJSXAttribute)(grandParentNode)) {
232
- // <foo bar={function () {}} />
233
166
  const openingElement = parentPath?.parentPath?.parentPath?.node;
234
167
  const prop = grandParentNode;
235
168
  id = t.jsxMemberExpression(
236
- // $FlowFixMe Flow error uncovered by typing Babel more strictly
237
169
  t.jsxMemberExpression(openingElement.name, t.jsxIdentifier("props")),
238
- // $FlowFixMe Flow error uncovered by typing Babel more strictly
239
170
  prop.name
240
171
  );
241
172
  }
242
173
  }
243
-
244
- // Collapse the name AST, if any, into a string.
245
174
  let name = getNameFromId(id);
246
175
  if (name == null) {
247
- // We couldn't find a name directly. Try the parent in certain cases.
248
176
  if (isAnyCallExpression(parent)) {
249
- // foo(function () {})
250
177
  const argIndex = parent.arguments.indexOf(node);
251
178
  if (argIndex !== -1) {
252
179
  const calleeName = getNameFromId(parent.callee);
253
- // var f = Object.freeze(function () {})
254
180
  if (argIndex === 0 && calleeName === "Object.freeze") {
255
181
  return getNameForPath(nullthrows(parentPath));
256
182
  }
257
- // var f = useCallback(function () {})
258
183
  if (
259
184
  argIndex === 0 &&
260
185
  (calleeName === "useCallback" || calleeName === "React.useCallback")
@@ -275,19 +200,13 @@ function getNameForPath(path) {
275
200
  if ((0, _types.isExportDefaultDeclaration)(parent)) {
276
201
  return "default";
277
202
  }
278
- // We couldn't infer a name at all.
279
203
  return ANONYMOUS_NAME;
280
204
  }
281
-
282
- // Annotate getters and setters.
283
205
  if (kind != null) {
284
206
  name = kind + "__" + name;
285
207
  }
286
-
287
- // Annotate members with the name of their containing object/class.
288
208
  if (propertyPath) {
289
209
  if ((0, _types.isClassBody)(propertyPath.parent)) {
290
- // $FlowFixMe Discovered when typing babel-traverse
291
210
  const className = getNameForPath(propertyPath.parentPath.parentPath);
292
211
  if (className !== ANONYMOUS_NAME) {
293
212
  const separator = propertyPath.node.static ? "." : "#";
@@ -302,8 +221,6 @@ function getNameForPath(path) {
302
221
  }
303
222
  return name;
304
223
  }
305
-
306
- // $FlowFixMe[deprecated-type]
307
224
  function isAnyCallExpression(node) {
308
225
  return (
309
226
  node.type === "CallExpression" ||
@@ -311,8 +228,6 @@ function isAnyCallExpression(node) {
311
228
  node.type === "OptionalCallExpression"
312
229
  );
313
230
  }
314
-
315
- // $FlowFixMe[deprecated-type]
316
231
  function isAnyMemberExpression(node) {
317
232
  return (
318
233
  node.type === "MemberExpression" ||
@@ -320,8 +235,6 @@ function isAnyMemberExpression(node) {
320
235
  node.type === "OptionalMemberExpression"
321
236
  );
322
237
  }
323
-
324
- // $FlowFixMe[deprecated-type]
325
238
  function isAnyIdentifier(node) {
326
239
  return (0, _types.isIdentifier)(node) || (0, _types.isJSXIdentifier)(node);
327
240
  }
@@ -399,12 +312,6 @@ function getNamePartsFromId(id) {
399
312
  return name ? [name] : [];
400
313
  }
401
314
  const DELIMITER_START_RE = /^[^A-Za-z0-9_$@]+/;
402
-
403
- /**
404
- * Strip the given prefix from `name`, if it occurs there, plus any delimiter
405
- * characters that follow (of which at least one is required). If an empty
406
- * string would be returned, return the original name instead.
407
- */
408
315
  function removeNamePrefix(name, namePrefix) {
409
316
  if (!namePrefix.length || !name.startsWith(namePrefix)) {
410
317
  return name;
@@ -416,31 +323,6 @@ function removeNamePrefix(name, namePrefix) {
416
323
  }
417
324
  return name;
418
325
  }
419
-
420
- /**
421
- * Encodes function name mappings as deltas in a Base64 VLQ format inspired by
422
- * the standard source map format.
423
- *
424
- * Mappings on different lines are separated with a single `;` (even if there
425
- * are multiple intervening lines).
426
- * Mappings on the same line are separated with `,`.
427
- *
428
- * The first mapping of a line has the fields:
429
- * [column delta, name delta, line delta]
430
- *
431
- * where the column delta is relative to the beginning of the line, the name
432
- * delta is relative to the previously occurring name, and the line delta is
433
- * relative to the previously occurring line.
434
- *
435
- * The 2...nth other mappings of a line have the fields:
436
- * [column delta, name delta]
437
- *
438
- * where both fields are relative to their previous running values. The line
439
- * delta is omitted since it is always 0 by definition.
440
- *
441
- * Lines and columns are both 0-based in the serialised format. In memory,
442
- * lines are 1-based while columns are 0-based.
443
- */
444
326
  class MappingEncoder {
445
327
  constructor() {
446
328
  this._namesMap = new Map();
@@ -466,7 +348,6 @@ class MappingEncoder {
466
348
  const lineDelta = this._line.next(start.line);
467
349
  const firstOfLine = this._mappings.pos === 0 || lineDelta > 0;
468
350
  if (lineDelta > 0) {
469
- // The next entry will have the line offset, so emit just one semicolon.
470
351
  this._mappings.markLines(1);
471
352
  this._column.reset(0);
472
353
  }
@@ -249,7 +249,7 @@ function getNameForPath(path: NodePath<>): string {
249
249
  return '<global>';
250
250
  }
251
251
 
252
- let {id} = (path: any);
252
+ let {id}: any = path;
253
253
  // has an `id` so we don't need to infer one
254
254
  if (node.id) {
255
255
  // $FlowFixMe Flow error uncovered by typing Babel more strictly
package/src/source-map.js CHANGED
@@ -1,27 +1,14 @@
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
- *
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const { BundleBuilder, createIndexMap } = require("./BundleBuilder");
15
4
  const composeSourceMaps = require("./composeSourceMaps");
16
5
  const Consumer = require("./Consumer");
17
- // We need to export this for `metro-symbolicate`
18
6
  const normalizeSourcePath = require("./Consumer/normalizeSourcePath");
19
7
  const {
20
8
  functionMapBabelPlugin,
21
9
  generateFunctionMap,
22
10
  } = require("./generateFunctionMap");
23
11
  const Generator = require("./Generator");
24
- // $FlowFixMe[untyped-import] - source-map
25
12
  const SourceMap = require("source-map");
26
13
  function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
27
14
  const modulesToProcess = modules.slice();
@@ -52,14 +39,9 @@ function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
52
39
  break;
53
40
  }
54
41
  if (!isBlocking) {
55
- // Keep the loop running but try to avoid blocking
56
- // for too long because this is not in a worker yet.
57
42
  const diff = process.hrtime(time);
58
43
  const NS_IN_MS = 1000000;
59
44
  if (diff[1] > 50 * NS_IN_MS) {
60
- // We've blocked for more than 50ms.
61
- // This code currently runs on the main thread,
62
- // so let's give Metro an opportunity to handle requests.
63
45
  setImmediate(workLoop);
64
46
  break;
65
47
  }
@@ -68,14 +50,6 @@ function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
68
50
  }
69
51
  workLoop();
70
52
  }
71
-
72
- /**
73
- * Creates a source map from modules with "raw mappings", i.e. an array of
74
- * tuples with either 2, 4, or 5 elements:
75
- * generated line, generated column, source line, source line, symbol name.
76
- * Accepts an `offsetLines` argument in case modules' code is to be offset in
77
- * the resulting bundle, e.g. by some prefix code.
78
- */
79
53
  function fromRawMappings(modules, offsetLines = 0) {
80
54
  let generator;
81
55
  fromRawMappingsImpl(
@@ -96,11 +70,6 @@ async function fromRawMappingsNonBlocking(modules, offsetLines = 0) {
96
70
  fromRawMappingsImpl(false, resolve, modules, offsetLines);
97
71
  });
98
72
  }
99
-
100
- /**
101
- * Transforms a standard source map object into a Raw Mappings object, to be
102
- * used across the bundler.
103
- */
104
73
  function toBabelSegments(sourceMap) {
105
74
  const rawMappings = [];
106
75
  new SourceMap.SourceMapConsumer(sourceMap).eachMapping((map) => {
@@ -152,7 +121,6 @@ function addMappingsForFile(generator, mappings, module, carryOver) {
152
121
  }
153
122
  function addMapping(generator, mapping, carryOver) {
154
123
  const line = mapping[0] + carryOver;
155
- // lines start at 1, columns start at 0
156
124
  const column = mapping[1];
157
125
  switch (mapping.length) {
158
126
  case 2: