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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro-source-map",
3
- "version": "0.73.2",
3
+ "version": "0.73.5",
4
4
  "description": "🚇 Source map generator for Metro.",
5
5
  "main": "src/source-map.js",
6
6
  "repository": {
@@ -13,11 +13,11 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@babel/traverse": "^7.14.0",
16
- "@babel/types": "^7.0.0",
16
+ "@babel/types": "^7.20.0",
17
17
  "invariant": "^2.2.4",
18
- "metro-symbolicate": "0.73.2",
18
+ "metro-symbolicate": "0.73.5",
19
19
  "nullthrows": "^1.1.1",
20
- "ob1": "0.73.2",
20
+ "ob1": "0.73.5",
21
21
  "source-map": "^0.5.6",
22
22
  "vlq": "^1.0.0"
23
23
  },
package/src/B64Builder.js CHANGED
@@ -8,14 +8,15 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const encode = require("./encode");
14
-
15
15
  const MAX_SEGMENT_LENGTH = 7;
16
16
  const ONE_MEG = 1024 * 1024;
17
17
  const COMMA = 0x2c;
18
18
  const SEMICOLON = 0x3b;
19
+
19
20
  /**
20
21
  * Efficient builder for base64 VLQ mappings strings.
21
22
  *
@@ -28,81 +29,70 @@ const SEMICOLON = 0x3b;
28
29
  * For details about source map terminology and specification, check
29
30
  * https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
30
31
  */
31
-
32
32
  class B64Builder {
33
33
  constructor() {
34
34
  this.buffer = Buffer.alloc(ONE_MEG);
35
35
  this.pos = 0;
36
36
  this.hasSegment = false;
37
37
  }
38
+
38
39
  /**
39
40
  * Adds `n` markers for generated lines to the mappings.
40
41
  */
41
-
42
42
  markLines(n) {
43
43
  if (n < 1) {
44
44
  return this;
45
45
  }
46
-
47
46
  this.hasSegment = false;
48
-
49
47
  if (this.pos + n >= this.buffer.length) {
50
48
  this._realloc();
51
49
  }
52
-
53
50
  while (n--) {
54
51
  this.buffer[this.pos++] = SEMICOLON;
55
52
  }
56
-
57
53
  return this;
58
54
  }
55
+
59
56
  /**
60
57
  * Starts a segment at the specified column offset in the current line.
61
58
  */
62
-
63
59
  startSegment(column) {
64
60
  if (this.hasSegment) {
65
61
  this._writeByte(COMMA);
66
62
  } else {
67
63
  this.hasSegment = true;
68
64
  }
69
-
70
65
  this.append(column);
71
66
  return this;
72
67
  }
68
+
73
69
  /**
74
70
  * Appends a single number to the mappings.
75
71
  */
76
-
77
72
  append(value) {
78
73
  if (this.pos + MAX_SEGMENT_LENGTH >= this.buffer.length) {
79
74
  this._realloc();
80
75
  }
81
-
82
76
  this.pos = encode(value, this.buffer, this.pos);
83
77
  return this;
84
78
  }
79
+
85
80
  /**
86
81
  * Returns the string representation of the mappings.
87
82
  */
88
-
89
83
  toString() {
90
84
  return this.buffer.toString("ascii", 0, this.pos);
91
85
  }
92
-
93
86
  _writeByte(byte) {
94
87
  if (this.pos === this.buffer.length) {
95
88
  this._realloc();
96
89
  }
97
-
98
90
  this.buffer[this.pos++] = byte;
99
91
  }
100
-
101
92
  _realloc() {
102
93
  const { buffer } = this;
103
94
  this.buffer = Buffer.alloc(buffer.length * 2);
104
95
  buffer.copy(this.buffer);
105
96
  }
106
97
  }
107
-
108
98
  module.exports = B64Builder;
@@ -8,6 +8,7 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const EMPTY_MAP = {
@@ -16,6 +17,7 @@ const EMPTY_MAP = {
16
17
  names: [],
17
18
  mappings: "A",
18
19
  };
20
+
19
21
  /**
20
22
  * Builds a source-mapped bundle by concatenating strings and their
21
23
  * corresponding source maps (if any).
@@ -30,7 +32,6 @@ const EMPTY_MAP = {
30
32
  * const code = builder.getCode();
31
33
  * const map = builder.getMap();
32
34
  */
33
-
34
35
  class BundleBuilder {
35
36
  constructor(file) {
36
37
  this._file = file;
@@ -40,7 +41,6 @@ class BundleBuilder {
40
41
  this._code = "";
41
42
  this._afterMappedContent = false;
42
43
  }
43
-
44
44
  _pushMapSection(map) {
45
45
  this._sections.push({
46
46
  map,
@@ -50,73 +50,56 @@ class BundleBuilder {
50
50
  },
51
51
  });
52
52
  }
53
-
54
53
  _endMappedContent() {
55
54
  if (this._afterMappedContent) {
56
55
  this._pushMapSection(EMPTY_MAP);
57
-
58
56
  this._afterMappedContent = false;
59
57
  }
60
58
  }
61
-
62
59
  append(code, map) {
63
60
  if (!code.length) {
64
61
  return this;
65
62
  }
66
-
67
63
  const { lineBreaks, lastLineColumns } = measureString(code);
68
-
69
64
  if (map) {
70
65
  this._pushMapSection(map);
71
-
72
66
  this._afterMappedContent = true;
73
67
  } else {
74
68
  this._endMappedContent();
75
69
  }
76
-
77
70
  this._afterMappedContent = !!map;
78
71
  this._line = this._line + lineBreaks;
79
-
80
72
  if (lineBreaks > 0) {
81
73
  this._column = lastLineColumns;
82
74
  } else {
83
75
  this._column = this._column + lastLineColumns;
84
76
  }
85
-
86
77
  this._code = this._code + code;
87
78
  return this;
88
79
  }
89
-
90
80
  getMap() {
91
81
  this._endMappedContent();
92
-
93
82
  return createIndexMap(this._file, this._sections);
94
83
  }
95
-
96
84
  getCode() {
97
85
  return this._code;
98
86
  }
99
87
  }
100
-
101
88
  const reLineBreak = /\r\n|\r|\n/g;
102
-
103
89
  function measureString(str) {
104
90
  let lineBreaks = 0;
105
91
  let match;
106
92
  let lastLineStart = 0;
107
-
108
93
  while ((match = reLineBreak.exec(str))) {
109
94
  ++lineBreaks;
110
95
  lastLineStart = match.index + match[0].length;
111
96
  }
112
-
113
97
  const lastLineColumns = str.length - lastLineStart;
114
98
  return {
115
99
  lineBreaks,
116
100
  lastLineColumns,
117
101
  };
118
102
  }
119
-
120
103
  function createIndexMap(file, sections) {
121
104
  return {
122
105
  version: 3,
@@ -124,7 +107,6 @@ function createIndexMap(file, sections) {
124
107
  sections,
125
108
  };
126
109
  }
127
-
128
110
  module.exports = {
129
111
  BundleBuilder,
130
112
  createIndexMap,
@@ -15,8 +15,8 @@ import type {IndexMap, IndexMapSection, MixedSourceMap} from './source-map';
15
15
 
16
16
  const EMPTY_MAP = {
17
17
  version: 3,
18
- sources: [],
19
- names: [],
18
+ sources: ([]: Array<string>),
19
+ names: ([]: Array<string>),
20
20
  mappings: 'A',
21
21
  };
22
22
 
@@ -8,43 +8,39 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const { GENERATED_ORDER, iterationOrderToString } = require("./constants");
15
+ const invariant = require("invariant");
14
16
 
15
- const invariant = require("invariant"); // Implementation details shared between MappingsConsumer and SectionsConsumer
16
-
17
+ // Implementation details shared between MappingsConsumer and SectionsConsumer
17
18
  class AbstractConsumer {
18
19
  constructor(sourceMap) {
19
20
  this._sourceMap = sourceMap;
20
21
  }
21
-
22
22
  originalPositionFor(generatedPosition) {
23
23
  invariant(false, "Not implemented");
24
24
  }
25
-
26
25
  generatedMappings() {
27
26
  invariant(false, "Not implemented");
28
27
  }
29
-
30
28
  eachMapping(callback, context = null, order = GENERATED_ORDER) {
31
29
  invariant(
32
30
  order === GENERATED_ORDER,
33
31
  `Iteration order not implemented: ${iterationOrderToString(order)}`
34
32
  );
35
-
36
33
  for (const mapping of this.generatedMappings()) {
37
34
  callback.call(context, mapping);
38
35
  }
39
- } // flowlint-next-line unsafe-getters-setters:off
36
+ }
40
37
 
38
+ // flowlint-next-line unsafe-getters-setters:off
41
39
  get file() {
42
40
  return this._sourceMap.file;
43
41
  }
44
-
45
42
  sourceContentFor(source, nullOnMissing) {
46
43
  invariant(false, "Not implemented");
47
44
  }
48
45
  }
49
-
50
46
  module.exports = AbstractConsumer;
@@ -8,6 +8,7 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const {
@@ -16,45 +17,39 @@ const {
16
17
  LEAST_UPPER_BOUND,
17
18
  ORIGINAL_ORDER,
18
19
  } = require("./constants");
19
-
20
20
  const createConsumer = require("./createConsumer");
21
+
21
22
  /**
22
23
  * A source map consumer that supports both "basic" and "indexed" source maps.
23
24
  * Uses `MappingsConsumer` and `SectionsConsumer` under the hood (via
24
25
  * `createConsumer`).
25
26
  */
26
-
27
27
  class DelegatingConsumer {
28
28
  static GENERATED_ORDER = GENERATED_ORDER;
29
29
  static ORIGINAL_ORDER = ORIGINAL_ORDER;
30
30
  static GREATEST_LOWER_BOUND = GREATEST_LOWER_BOUND;
31
31
  static LEAST_UPPER_BOUND = LEAST_UPPER_BOUND;
32
-
33
32
  // $FlowFixMe[incompatible-return]
34
33
  constructor(sourceMap) {
35
34
  this._rootConsumer = createConsumer(sourceMap);
36
35
  return this._rootConsumer;
37
36
  }
38
-
39
37
  originalPositionFor(generatedPosition) {
40
38
  return this._rootConsumer.originalPositionFor(generatedPosition);
41
39
  }
42
-
43
40
  generatedMappings() {
44
41
  return this._rootConsumer.generatedMappings();
45
42
  }
46
-
47
43
  eachMapping(callback, context, order) {
48
44
  return this._rootConsumer.eachMapping(callback, context, order);
49
- } // flowlint-next-line unsafe-getters-setters:off
45
+ }
50
46
 
47
+ // flowlint-next-line unsafe-getters-setters:off
51
48
  get file() {
52
49
  return this._rootConsumer.file;
53
50
  }
54
-
55
51
  sourceContentFor(source, nullOnMissing) {
56
52
  return this._rootConsumer.sourceContentFor(source, nullOnMissing);
57
53
  }
58
54
  }
59
-
60
55
  module.exports = DelegatingConsumer;
@@ -8,10 +8,10 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const AbstractConsumer = require("./AbstractConsumer");
14
-
15
15
  const {
16
16
  EMPTY_POSITION,
17
17
  FIRST_COLUMN,
@@ -19,21 +19,16 @@ const {
19
19
  GREATEST_LOWER_BOUND,
20
20
  lookupBiasToString,
21
21
  } = require("./constants");
22
-
23
22
  const normalizeSourcePath = require("./normalizeSourcePath");
24
-
25
23
  const { greatestLowerBound } = require("./search");
26
-
27
24
  const invariant = require("invariant");
28
-
29
25
  const { add, add0, get0, inc, sub } = require("ob1");
30
-
31
26
  const { decode: decodeVlq } = require("vlq");
27
+
32
28
  /**
33
29
  * A source map consumer that supports "basic" source maps (that have a
34
30
  * `mappings` field and no sections).
35
31
  */
36
-
37
32
  class MappingsConsumer extends AbstractConsumer {
38
33
  constructor(sourceMap) {
39
34
  super(sourceMap);
@@ -41,14 +36,13 @@ class MappingsConsumer extends AbstractConsumer {
41
36
  this._decodedMappings = null;
42
37
  this._normalizedSources = null;
43
38
  }
44
-
45
39
  originalPositionFor(generatedPosition) {
46
40
  const { line, column } = generatedPosition;
47
-
48
41
  if (line == null || column == null) {
49
- return { ...EMPTY_POSITION };
42
+ return {
43
+ ...EMPTY_POSITION,
44
+ };
50
45
  }
51
-
52
46
  if (generatedPosition.bias != null) {
53
47
  invariant(
54
48
  generatedPosition.bias === GREATEST_LOWER_BOUND,
@@ -58,9 +52,7 @@ class MappingsConsumer extends AbstractConsumer {
58
52
  )}`
59
53
  );
60
54
  }
61
-
62
55
  const mappings = this._decodeAndCacheMappings();
63
-
64
56
  const index = greatestLowerBound(
65
57
  mappings,
66
58
  {
@@ -71,11 +63,9 @@ class MappingsConsumer extends AbstractConsumer {
71
63
  if (position.line === mapping.generatedLine) {
72
64
  return get0(sub(position.column, mapping.generatedColumn));
73
65
  }
74
-
75
66
  return get0(sub(position.line, mapping.generatedLine));
76
67
  }
77
68
  );
78
-
79
69
  if (
80
70
  index != null &&
81
71
  mappings[index].generatedLine === generatedPosition.line
@@ -88,10 +78,10 @@ class MappingsConsumer extends AbstractConsumer {
88
78
  column: mapping.originalColumn,
89
79
  };
90
80
  }
91
-
92
- return { ...EMPTY_POSITION };
81
+ return {
82
+ ...EMPTY_POSITION,
83
+ };
93
84
  }
94
-
95
85
  *_decodeMappings() {
96
86
  let generatedLine = FIRST_LINE;
97
87
  let generatedColumn = FIRST_COLUMN;
@@ -99,46 +89,36 @@ class MappingsConsumer extends AbstractConsumer {
99
89
  let originalColumn = FIRST_COLUMN;
100
90
  let nameIndex = add0(0);
101
91
  let sourceIndex = add0(0);
102
-
103
92
  const normalizedSources = this._normalizeAndCacheSources();
104
-
105
93
  const { mappings: mappingsRaw, names } = this._sourceMap;
106
94
  let next;
107
95
  const vlqCache = new Map();
108
-
109
96
  for (let i = 0; i < mappingsRaw.length; i = next) {
110
97
  switch (mappingsRaw[i]) {
111
98
  case ";":
112
99
  generatedLine = inc(generatedLine);
113
100
  generatedColumn = FIRST_COLUMN;
114
-
115
101
  /* falls through */
116
-
117
102
  case ",":
118
103
  next = i + 1;
119
104
  continue;
120
105
  }
121
-
122
106
  findNext: for (next = i + 1; next < mappingsRaw.length; ++next) {
123
107
  switch (mappingsRaw[next]) {
124
108
  case ";":
125
109
  /* falls through */
126
-
127
110
  case ",":
128
111
  break findNext;
129
112
  }
130
113
  }
131
-
132
114
  const mappingRaw = mappingsRaw.slice(i, next);
133
115
  let decodedVlqValues;
134
-
135
116
  if (vlqCache.has(mappingRaw)) {
136
117
  decodedVlqValues = vlqCache.get(mappingRaw);
137
118
  } else {
138
119
  decodedVlqValues = decodeVlq(mappingRaw);
139
120
  vlqCache.set(mappingRaw, decodedVlqValues);
140
121
  }
141
-
142
122
  invariant(Array.isArray(decodedVlqValues), "Decoding VLQ tuple failed");
143
123
  const [
144
124
  generatedColumnDelta,
@@ -158,7 +138,6 @@ class MappingsConsumer extends AbstractConsumer {
158
138
  originalLine: null,
159
139
  originalColumn: null,
160
140
  };
161
-
162
141
  if (sourceIndexDelta != null) {
163
142
  sourceIndex = add(sourceIndex, sourceIndexDelta);
164
143
  mapping.source = normalizedSources[get0(sourceIndex)];
@@ -168,71 +147,54 @@ class MappingsConsumer extends AbstractConsumer {
168
147
  originalColumn = add(originalColumn, originalColumnDelta);
169
148
  mapping.originalLine = originalLine;
170
149
  mapping.originalColumn = originalColumn;
171
-
172
150
  if (nameIndexDelta != null) {
173
151
  nameIndex = add(nameIndex, nameIndexDelta);
174
152
  mapping.name = names[get0(nameIndex)];
175
153
  }
176
154
  }
177
-
178
155
  yield mapping;
179
156
  }
180
157
  }
181
-
182
158
  _normalizeAndCacheSources() {
183
159
  if (!this._normalizedSources) {
184
160
  this._normalizedSources = this._sourceMap.sources.map((source) =>
185
161
  normalizeSourcePath(source, this._sourceMap)
186
162
  );
187
163
  }
188
-
189
164
  return this._normalizedSources;
190
165
  }
191
-
192
166
  _decodeAndCacheMappings() {
193
167
  if (!this._decodedMappings) {
194
168
  this._decodedMappings = [...this._decodeMappings()];
195
169
  }
196
-
197
170
  return this._decodedMappings;
198
171
  }
199
-
200
172
  generatedMappings() {
201
173
  return this._decodeAndCacheMappings();
202
174
  }
203
-
204
175
  _indexOfSource(source) {
205
176
  const idx = this._normalizeAndCacheSources().indexOf(
206
177
  normalizeSourcePath(source, this._sourceMap)
207
178
  );
208
-
209
179
  if (idx === -1) {
210
180
  return null;
211
181
  }
212
-
213
182
  return add0(idx);
214
183
  }
215
-
216
184
  sourceContentFor(source, nullOnMissing) {
217
185
  var _sourcesContent$get;
218
-
219
186
  const { sourcesContent } = this._sourceMap;
220
-
221
187
  if (!sourcesContent) {
222
188
  return null;
223
189
  }
224
-
225
190
  const idx = this._indexOfSource(source);
226
-
227
191
  if (idx == null) {
228
192
  return null;
229
193
  }
230
-
231
194
  return (_sourcesContent$get = sourcesContent[get0(idx)]) !== null &&
232
195
  _sourcesContent$get !== void 0
233
196
  ? _sourcesContent$get
234
197
  : null;
235
198
  }
236
199
  }
237
-
238
200
  module.exports = MappingsConsumer;
@@ -104,7 +104,7 @@ class MappingsConsumer extends AbstractConsumer implements IConsumer {
104
104
 
105
105
  const {mappings: mappingsRaw, names} = this._sourceMap;
106
106
  let next;
107
- const vlqCache = new Map();
107
+ const vlqCache = new Map<string, any>();
108
108
  for (let i = 0; i < mappingsRaw.length; i = next) {
109
109
  switch (mappingsRaw[i]) {
110
110
  case ';':
@@ -8,24 +8,20 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const AbstractConsumer = require("./AbstractConsumer");
14
-
15
15
  const { EMPTY_POSITION, FIRST_COLUMN, FIRST_LINE } = require("./constants");
16
-
17
16
  const createConsumer = require("./createConsumer");
18
-
19
17
  const { subtractOffsetFromPosition } = require("./positionMath");
20
-
21
18
  const { greatestLowerBound } = require("./search");
22
-
23
19
  const { add, add0, get0, get1, sub, sub1 } = require("ob1");
20
+
24
21
  /**
25
22
  * A source map consumer that supports "indexed" source maps (that have a
26
23
  * `sections` field and no top-level mappings).
27
24
  */
28
-
29
25
  class SectionsConsumer extends AbstractConsumer {
30
26
  constructor(sourceMap) {
31
27
  super(sourceMap);
@@ -38,24 +34,21 @@ class SectionsConsumer extends AbstractConsumer {
38
34
  return [generatedOffset, consumer];
39
35
  });
40
36
  }
41
-
42
37
  originalPositionFor(generatedPosition) {
43
38
  const [generatedOffset, consumer] =
44
39
  this._consumerForPosition(generatedPosition) || [];
45
-
46
40
  if (!consumer) {
47
- return { ...EMPTY_POSITION };
41
+ return {
42
+ ...EMPTY_POSITION,
43
+ };
48
44
  }
49
-
50
45
  return consumer.originalPositionFor(
51
46
  subtractOffsetFromPosition(generatedPosition, generatedOffset)
52
47
  );
53
48
  }
54
-
55
49
  *generatedMappings() {
56
50
  for (const [generatedOffset, consumer] of this._consumers) {
57
51
  let first = true;
58
-
59
52
  for (const mapping of consumer.generatedMappings()) {
60
53
  if (
61
54
  first &&
@@ -70,7 +63,6 @@ class SectionsConsumer extends AbstractConsumer {
70
63
  originalColumn: null,
71
64
  };
72
65
  }
73
-
74
66
  first = false;
75
67
  yield {
76
68
  ...mapping,
@@ -83,42 +75,33 @@ class SectionsConsumer extends AbstractConsumer {
83
75
  }
84
76
  }
85
77
  }
86
-
87
78
  _consumerForPosition(generatedPosition) {
88
79
  const { line, column } = generatedPosition;
89
-
90
80
  if (line == null || column == null) {
91
81
  return null;
92
82
  }
93
-
94
83
  const index = greatestLowerBound(
95
84
  this._consumers,
96
85
  generatedPosition,
97
86
  (position, [offset]) => {
98
87
  const line0 = sub1(line);
99
88
  const column0 = column;
100
-
101
89
  if (line0 === offset.lines) {
102
90
  return get0(sub(column0, offset.columns));
103
91
  }
104
-
105
92
  return get0(sub(line0, offset.lines));
106
93
  }
107
94
  );
108
95
  return index != null ? this._consumers[index] : null;
109
96
  }
110
-
111
97
  sourceContentFor(source, nullOnMissing) {
112
98
  for (const [_, consumer] of this._consumers) {
113
99
  const content = consumer.sourceContentFor(source, nullOnMissing);
114
-
115
100
  if (content != null) {
116
101
  return content;
117
102
  }
118
103
  }
119
-
120
104
  return null;
121
105
  }
122
106
  }
123
-
124
107
  module.exports = SectionsConsumer;
@@ -8,10 +8,10 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const { add0, add1 } = require("ob1");
14
-
15
15
  const FIRST_COLUMN = add0(0);
16
16
  const FIRST_LINE = add1(0);
17
17
  const GENERATED_ORDER = "GENERATED_ORDER";
@@ -24,15 +24,12 @@ const EMPTY_POSITION = Object.freeze({
24
24
  line: null,
25
25
  column: null,
26
26
  });
27
-
28
27
  function iterationOrderToString(x) {
29
28
  return x;
30
29
  }
31
-
32
30
  function lookupBiasToString(x) {
33
31
  return x;
34
32
  }
35
-
36
33
  module.exports = {
37
34
  FIRST_COLUMN,
38
35
  FIRST_LINE,