metro-source-map 0.73.2 → 0.73.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.
@@ -8,25 +8,22 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const invariant = require("invariant");
14
-
15
15
  function createConsumer(sourceMap) {
16
16
  invariant(
17
17
  sourceMap.version === "3" || sourceMap.version === 3,
18
18
  `Unrecognized source map format version: ${sourceMap.version}`
19
19
  );
20
-
21
20
  const MappingsConsumer = require("./MappingsConsumer");
21
+ const SectionsConsumer = require("./SectionsConsumer");
22
22
 
23
- const SectionsConsumer = require("./SectionsConsumer"); // eslint-disable-next-line lint/strictly-null
24
-
23
+ // eslint-disable-next-line lint/strictly-null
25
24
  if (sourceMap.mappings === undefined) {
26
25
  return new SectionsConsumer(sourceMap);
27
26
  }
28
-
29
27
  return new MappingsConsumer(sourceMap);
30
28
  }
31
-
32
29
  module.exports = createConsumer;
@@ -8,8 +8,9 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
- "use strict"; // Implements an API-compatible subset of source-map's `SourceMapConsumer`.
12
11
 
13
- const DelegatingConsumer = require("./DelegatingConsumer");
12
+ "use strict";
14
13
 
14
+ // Implements an API-compatible subset of source-map's `SourceMapConsumer`.
15
+ const DelegatingConsumer = require("./DelegatingConsumer");
15
16
  module.exports = DelegatingConsumer;
@@ -8,27 +8,29 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
- "use strict"; // flowlint-next-line untyped-import:off
12
11
 
13
- const util = require("source-map/lib/util"); // Extracted from source-map@0.5.6's SourceMapConsumer
12
+ "use strict";
14
13
 
14
+ // flowlint-next-line untyped-import:off
15
+ const util = require("source-map/lib/util");
16
+
17
+ // Extracted from source-map@0.5.6's SourceMapConsumer
15
18
  function normalizeSourcePath(sourceInput, map) {
16
19
  const { sourceRoot } = map;
17
20
  let source = sourceInput;
18
- source = String(source); // Some source maps produce relative source paths like "./foo.js" instead of
21
+ source = String(source);
22
+ // Some source maps produce relative source paths like "./foo.js" instead of
19
23
  // "foo.js". Normalize these first so that future comparisons will succeed.
20
24
  // See bugzil.la/1090768.
21
-
22
- source = util.normalize(source); // Always ensure that absolute sources are internally stored relative to
25
+ source = util.normalize(source);
26
+ // Always ensure that absolute sources are internally stored relative to
23
27
  // the source root, if the source root is absolute. Not doing this would
24
28
  // be particularly problematic when the source root is a prefix of the
25
29
  // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
26
-
27
30
  source =
28
31
  sourceRoot != null && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
29
32
  ? util.relative(sourceRoot, source)
30
33
  : source;
31
34
  return source;
32
35
  }
33
-
34
36
  module.exports = normalizeSourcePath;
@@ -8,10 +8,10 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const { add, add0, add1, neg } = require("ob1");
14
-
15
15
  function shiftPositionByOffset(pos, offset) {
16
16
  return {
17
17
  ...pos,
@@ -19,7 +19,6 @@ function shiftPositionByOffset(pos, offset) {
19
19
  column: pos.column != null ? add(pos.column, offset.columns) : null,
20
20
  };
21
21
  }
22
-
23
22
  function subtractOffsetFromPosition(pos, offset) {
24
23
  if (pos.line === add1(offset.lines)) {
25
24
  return shiftPositionByOffset(pos, {
@@ -27,13 +26,11 @@ function subtractOffsetFromPosition(pos, offset) {
27
26
  columns: neg(offset.columns),
28
27
  });
29
28
  }
30
-
31
29
  return shiftPositionByOffset(pos, {
32
30
  lines: neg(offset.lines),
33
31
  columns: add0(0),
34
32
  });
35
33
  }
36
-
37
34
  module.exports = {
38
35
  shiftPositionByOffset,
39
36
  subtractOffsetFromPosition,
@@ -8,6 +8,7 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  function greatestLowerBound(elements, target, comparator) {
@@ -15,12 +16,10 @@ function greatestLowerBound(elements, target, comparator) {
15
16
  let it = 0;
16
17
  let count = elements.length;
17
18
  let step;
18
-
19
19
  while (count > 0) {
20
20
  it = first;
21
21
  step = Math.floor(count / 2);
22
22
  it = it + step;
23
-
24
23
  if (comparator(target, elements[it]) >= 0) {
25
24
  first = ++it;
26
25
  count = count - (step + 1);
@@ -28,10 +27,8 @@ function greatestLowerBound(elements, target, comparator) {
28
27
  count = step;
29
28
  }
30
29
  }
31
-
32
30
  return first ? first - 1 : null;
33
31
  }
34
-
35
32
  module.exports = {
36
33
  greatestLowerBound,
37
34
  };
@@ -8,4 +8,5 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
package/src/Generator.js CHANGED
@@ -8,9 +8,11 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const B64Builder = require("./B64Builder");
15
+
14
16
  /**
15
17
  * Generates a source map from raw mappings.
16
18
  *
@@ -22,7 +24,6 @@ const B64Builder = require("./B64Builder");
22
24
  *
23
25
  * Mappings have to be passed in the order appearance in the generated source.
24
26
  */
25
-
26
27
  class Generator {
27
28
  constructor() {
28
29
  this.builder = new B64Builder();
@@ -41,29 +42,28 @@ class Generator {
41
42
  this.sourcesContent = [];
42
43
  this.x_facebook_sources = [];
43
44
  }
45
+
44
46
  /**
45
47
  * Mark the beginning of a new source file.
46
48
  */
47
-
48
49
  startFile(file, code, functionMap) {
49
50
  this.source = this.sources.push(file) - 1;
50
51
  this.sourcesContent.push(code);
51
52
  this.x_facebook_sources.push(functionMap ? [functionMap] : null);
52
53
  }
54
+
53
55
  /**
54
56
  * Mark the end of the current source file
55
57
  */
56
-
57
58
  endFile() {
58
59
  this.source = -1;
59
60
  }
61
+
60
62
  /**
61
63
  * Adds a mapping for generated code without a corresponding source location.
62
64
  */
63
-
64
65
  addSimpleMapping(generatedLine, generatedColumn) {
65
66
  const last = this.last;
66
-
67
67
  if (
68
68
  this.source === -1 ||
69
69
  (generatedLine === last.generatedLine &&
@@ -76,20 +76,18 @@ class Generator {
76
76
  : "Mapping is for a position preceding an earlier mapping";
77
77
  throw new Error(msg);
78
78
  }
79
-
80
79
  if (generatedLine > last.generatedLine) {
81
80
  this.builder.markLines(generatedLine - last.generatedLine);
82
81
  last.generatedLine = generatedLine;
83
82
  last.generatedColumn = 0;
84
83
  }
85
-
86
84
  this.builder.startSegment(generatedColumn - last.generatedColumn);
87
85
  last.generatedColumn = generatedColumn;
88
86
  }
87
+
89
88
  /**
90
89
  * Adds a mapping for generated code with a corresponding source location.
91
90
  */
92
-
93
91
  addSourceMapping(generatedLine, generatedColumn, sourceLine, sourceColumn) {
94
92
  this.addSimpleMapping(generatedLine, generatedColumn);
95
93
  const last = this.last;
@@ -101,10 +99,10 @@ class Generator {
101
99
  last.sourceColumn = sourceColumn;
102
100
  last.sourceLine = sourceLine;
103
101
  }
102
+
104
103
  /**
105
104
  * Adds a mapping for code with a corresponding source location + symbol name.
106
105
  */
107
-
108
106
  addNamedSourceMapping(
109
107
  generatedLine,
110
108
  generatedColumn,
@@ -123,13 +121,12 @@ class Generator {
123
121
  this.builder.append(nameIndex - last.name);
124
122
  last.name = nameIndex;
125
123
  }
124
+
126
125
  /**
127
126
  * Return the source map as object.
128
127
  */
129
-
130
128
  toMap(file, options) {
131
129
  let content, sourcesMetadata;
132
-
133
130
  if (options && options.excludeSource) {
134
131
  content = {};
135
132
  } else {
@@ -137,7 +134,6 @@ class Generator {
137
134
  sourcesContent: this.sourcesContent.slice(),
138
135
  };
139
136
  }
140
-
141
137
  if (this.hasSourcesMetadata()) {
142
138
  sourcesMetadata = {
143
139
  x_facebook_sources: JSON.parse(JSON.stringify(this.x_facebook_sources)),
@@ -145,13 +141,11 @@ class Generator {
145
141
  } else {
146
142
  sourcesMetadata = {};
147
143
  }
148
-
149
144
  return {
150
145
  version: 3,
151
146
  file,
152
147
  sources: this.sources.slice(),
153
148
  ...content,
154
-
155
149
  /* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment suppresses an
156
150
  * error found when Flow v0.111 was deployed. To see the error, delete
157
151
  * this comment and run Flow. */
@@ -160,21 +154,19 @@ class Generator {
160
154
  mappings: this.builder.toString(),
161
155
  };
162
156
  }
157
+
163
158
  /**
164
159
  * Return the source map as string.
165
160
  *
166
161
  * This is ~2.5x faster than calling `JSON.stringify(generator.toMap())`
167
162
  */
168
-
169
163
  toString(file, options) {
170
164
  let content, sourcesMetadata;
171
-
172
165
  if (options && options.excludeSource) {
173
166
  content = "";
174
167
  } else {
175
168
  content = `"sourcesContent":${JSON.stringify(this.sourcesContent)},`;
176
169
  }
177
-
178
170
  if (this.hasSourcesMetadata()) {
179
171
  sourcesMetadata = `"x_facebook_sources":${JSON.stringify(
180
172
  this.x_facebook_sources
@@ -182,7 +174,6 @@ class Generator {
182
174
  } else {
183
175
  sourcesMetadata = "";
184
176
  }
185
-
186
177
  return (
187
178
  "{" +
188
179
  '"version":3,' +
@@ -195,38 +186,32 @@ class Generator {
195
186
  "}"
196
187
  );
197
188
  }
189
+
198
190
  /**
199
191
  * Determine whether we need to write the `x_facebook_sources` field.
200
192
  * If the metadata is all `null`s, we can omit the field entirely.
201
193
  */
202
-
203
194
  hasSourcesMetadata() {
204
195
  return this.x_facebook_sources.some(
205
196
  (metadata) => metadata != null && metadata.some((value) => value != null)
206
197
  );
207
198
  }
208
199
  }
209
-
210
200
  class IndexedSet {
211
201
  constructor() {
212
202
  this.map = new Map();
213
203
  this.nextIndex = 0;
214
204
  }
215
-
216
205
  indexFor(x) {
217
206
  let index = this.map.get(x);
218
-
219
207
  if (index == null) {
220
208
  index = this.nextIndex++;
221
209
  this.map.set(x, index);
222
210
  }
223
-
224
211
  return index;
225
212
  }
226
-
227
213
  items() {
228
214
  return Array.from(this.map.keys());
229
215
  }
230
216
  }
231
-
232
217
  module.exports = Generator;
@@ -8,22 +8,22 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const Consumer = require("./Consumer");
15
+ const { SourceMapGenerator } = require("source-map");
14
16
 
15
- const { SourceMapGenerator } = require("source-map"); // TODO(t67648443): Bypass the `sort-requires` rule for this file because of a dependency cycle.
16
-
17
- Consumer; // Originally based on https://github.com/jakobwesthoff/source-map-merger
17
+ // TODO(t67648443): Bypass the `sort-requires` rule for this file because of a dependency cycle.
18
+ Consumer;
18
19
 
20
+ // Originally based on https://github.com/jakobwesthoff/source-map-merger
19
21
  function composeSourceMaps(maps) {
20
22
  // NOTE: require() here to break dependency cycle
21
23
  const SourceMetadataMapConsumer = require("metro-symbolicate/src/SourceMetadataMapConsumer");
22
-
23
24
  if (maps.length < 1) {
24
25
  throw new Error("composeSourceMaps: Expected at least one map");
25
26
  }
26
-
27
27
  const firstMap = maps[0];
28
28
  const consumers = maps
29
29
  .map(function (map) {
@@ -59,24 +59,19 @@ function composeSourceMaps(maps) {
59
59
  composedMap.sourcesContent = composedMap.sources.map((source) =>
60
60
  consumers[consumers.length - 1].sourceContentFor(source, true)
61
61
  );
62
-
63
62
  if (composedMap.sourcesContent.every((content) => content == null)) {
64
63
  delete composedMap.sourcesContent;
65
64
  }
66
-
67
65
  const metadataConsumer = new SourceMetadataMapConsumer(firstMap);
68
66
  composedMap.x_facebook_sources = metadataConsumer.toArray(
69
67
  composedMap.sources
70
68
  );
71
69
  const function_offsets = maps[maps.length - 1].x_hermes_function_offsets;
72
-
73
70
  if (function_offsets) {
74
71
  composedMap.x_hermes_function_offsets = function_offsets;
75
72
  }
76
-
77
73
  return composedMap;
78
74
  }
79
-
80
75
  function findOriginalPosition(consumers, generatedLine, generatedColumn) {
81
76
  let currentLine = generatedLine;
82
77
  let currentColumn = generatedColumn;
@@ -86,7 +81,6 @@ function findOriginalPosition(consumers, generatedLine, generatedColumn) {
86
81
  source: null,
87
82
  name: null,
88
83
  };
89
-
90
84
  for (const consumer of consumers) {
91
85
  if (currentLine == null || currentColumn == null) {
92
86
  return {
@@ -96,14 +90,12 @@ function findOriginalPosition(consumers, generatedLine, generatedColumn) {
96
90
  name: null,
97
91
  };
98
92
  }
99
-
100
93
  original = consumer.originalPositionFor({
101
94
  line: currentLine,
102
95
  column: currentColumn,
103
96
  });
104
97
  currentLine = original.line;
105
98
  currentColumn = original.column;
106
-
107
99
  if (currentLine == null) {
108
100
  return {
109
101
  line: null,
@@ -112,9 +104,8 @@ function findOriginalPosition(consumers, generatedLine, generatedColumn) {
112
104
  name: null,
113
105
  };
114
106
  }
115
- } // $FlowFixMe[incompatible-return] `Number0`, `Number1` is incompatible with number
116
-
107
+ }
108
+ // $FlowFixMe[incompatible-return] `Number0`, `Number1` is incompatible with number
117
109
  return original;
118
110
  }
119
-
120
111
  module.exports = composeSourceMaps;
package/src/encode.js CHANGED
@@ -48,15 +48,19 @@
48
48
  */
49
49
 
50
50
  /* eslint-disable no-bitwise */
51
- "use strict"; // A map of values to characters for the b64 encoding
52
51
 
52
+ "use strict";
53
+
54
+ // A map of values to characters for the b64 encoding
53
55
  const CHAR_MAP = [
54
56
  0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
55
57
  0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
56
58
  0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
57
59
  0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
58
60
  0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f,
59
- ]; // A single base 64 digit can contain 6 bits of data. For the base 64 variable
61
+ ];
62
+
63
+ // A single base 64 digit can contain 6 bits of data. For the base 64 variable
60
64
  // length quantities we use in the source map spec, the first bit is the sign,
61
65
  // the next four bits are the actual value, and the 6th bit is the
62
66
  // continuation bit. The continuation bit tells us whether there are more
@@ -68,23 +72,27 @@ const CHAR_MAP = [
68
72
  // V V
69
73
  // 101011
70
74
 
71
- const VLQ_BASE_SHIFT = 5; // binary: 100000
75
+ const VLQ_BASE_SHIFT = 5;
72
76
 
73
- const VLQ_BASE = 1 << VLQ_BASE_SHIFT; // binary: 011111
77
+ // binary: 100000
78
+ const VLQ_BASE = 1 << VLQ_BASE_SHIFT;
74
79
 
75
- const VLQ_BASE_MASK = VLQ_BASE - 1; // binary: 100000
80
+ // binary: 011111
81
+ const VLQ_BASE_MASK = VLQ_BASE - 1;
76
82
 
83
+ // binary: 100000
77
84
  const VLQ_CONTINUATION_BIT = VLQ_BASE;
85
+
78
86
  /**
79
87
  * Converts from a two-complement value to a value where the sign bit is
80
88
  * placed in the least significant bit. For example, as decimals:
81
89
  * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
82
90
  * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
83
91
  */
84
-
85
92
  function toVLQSigned(value) {
86
93
  return value < 0 ? (-value << 1) + 1 : (value << 1) + 0;
87
94
  }
95
+
88
96
  /**
89
97
  * Encodes a number to base64 VLQ format and appends it to the passed-in buffer
90
98
  *
@@ -94,25 +102,19 @@ function toVLQSigned(value) {
94
102
  * DON'T ADD MORE COMMENTS TO THIS FUNCTION TO KEEP ITS LENGTH SHORT ENOUGH FOR
95
103
  * V8 OPTIMIZATION!
96
104
  */
97
-
98
105
  function encode(value, buffer, position) {
99
106
  let vlq = toVLQSigned(value);
100
107
  let digit;
101
-
102
108
  do {
103
109
  digit = vlq & VLQ_BASE_MASK;
104
110
  vlq = vlq >>> VLQ_BASE_SHIFT;
105
-
106
111
  if (vlq > 0) {
107
112
  // There are still more digits in this value, so we must make sure the
108
113
  // continuation bit is marked.
109
114
  digit = digit | VLQ_CONTINUATION_BIT;
110
115
  }
111
-
112
116
  buffer[position++] = CHAR_MAP[digit];
113
117
  } while (vlq > 0);
114
-
115
118
  return position;
116
119
  }
117
-
118
120
  module.exports = encode;