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 +4 -4
- package/src/B64Builder.js +6 -16
- package/src/BundleBuilder.js +2 -20
- package/src/BundleBuilder.js.flow +2 -2
- package/src/Consumer/AbstractConsumer.js +5 -9
- package/src/Consumer/DelegatingConsumer.js +4 -9
- package/src/Consumer/MappingsConsumer.js +8 -46
- package/src/Consumer/MappingsConsumer.js.flow +1 -1
- package/src/Consumer/SectionsConsumer.js +5 -22
- package/src/Consumer/constants.js +1 -4
- package/src/Consumer/createConsumer.js +3 -6
- package/src/Consumer/index.js +3 -2
- package/src/Consumer/normalizeSourcePath.js +9 -7
- package/src/Consumer/positionMath.js +1 -4
- package/src/Consumer/search.js +1 -4
- package/src/Consumer/types.flow.js +1 -0
- package/src/Generator.js +10 -25
- package/src/composeSourceMaps.js +7 -16
- package/src/encode.js +14 -12
- package/src/generateFunctionMap.js +28 -97
- package/src/generateFunctionMap.js.flow +1 -1
- package/src/source-map.js +7 -37
- package/src/source-map.js.flow +1 -1
|
@@ -8,24 +8,18 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
|
+
|
|
11
12
|
"use strict";
|
|
12
13
|
|
|
13
14
|
var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
|
14
|
-
|
|
15
15
|
var _types = require("@babel/types");
|
|
16
|
-
|
|
17
16
|
function _interopRequireDefault(obj) {
|
|
18
17
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
const B64Builder = require("./B64Builder");
|
|
22
|
-
|
|
23
20
|
const t = require("@babel/types");
|
|
24
|
-
|
|
25
21
|
const nullthrows = require("nullthrows");
|
|
26
|
-
|
|
27
22
|
const fsPath = require("path");
|
|
28
|
-
|
|
29
23
|
/**
|
|
30
24
|
* Generate a map of source positions to function names. The names are meant to
|
|
31
25
|
* describe the stack frame in an error trace and may contain more contextual
|
|
@@ -39,13 +33,13 @@ function generateFunctionMap(ast, context) {
|
|
|
39
33
|
forEachMapping(ast, context, (mapping) => encoder.push(mapping));
|
|
40
34
|
return encoder.getResult();
|
|
41
35
|
}
|
|
36
|
+
|
|
42
37
|
/**
|
|
43
38
|
* Same as generateFunctionMap, but returns the raw array of mappings instead
|
|
44
39
|
* of encoding it for use in a source map.
|
|
45
40
|
*
|
|
46
41
|
* Lines are 1-based and columns are 0-based.
|
|
47
42
|
*/
|
|
48
|
-
|
|
49
43
|
function generateFunctionMappingsArray(ast, context) {
|
|
50
44
|
const mappings = [];
|
|
51
45
|
forEachMapping(ast, context, (mapping) => {
|
|
@@ -53,11 +47,11 @@ function generateFunctionMappingsArray(ast, context) {
|
|
|
53
47
|
});
|
|
54
48
|
return mappings;
|
|
55
49
|
}
|
|
50
|
+
|
|
56
51
|
/**
|
|
57
52
|
* Traverses a Babel AST and calls the supplied callback with function name
|
|
58
53
|
* mappings, one at a time.
|
|
59
54
|
*/
|
|
60
|
-
|
|
61
55
|
function forEachMapping(ast, context, pushMapping) {
|
|
62
56
|
const nameStack = [];
|
|
63
57
|
let tailPos = {
|
|
@@ -65,11 +59,9 @@ function forEachMapping(ast, context, pushMapping) {
|
|
|
65
59
|
column: 0,
|
|
66
60
|
};
|
|
67
61
|
let tailName = null;
|
|
68
|
-
|
|
69
62
|
function advanceToPos(pos) {
|
|
70
63
|
if (tailPos && positionGreater(pos, tailPos)) {
|
|
71
64
|
const name = nameStack[0].name; // We always have at least Program
|
|
72
|
-
|
|
73
65
|
if (name !== tailName) {
|
|
74
66
|
pushMapping({
|
|
75
67
|
name,
|
|
@@ -81,10 +73,8 @@ function forEachMapping(ast, context, pushMapping) {
|
|
|
81
73
|
tailName = name;
|
|
82
74
|
}
|
|
83
75
|
}
|
|
84
|
-
|
|
85
76
|
tailPos = pos;
|
|
86
77
|
}
|
|
87
|
-
|
|
88
78
|
function pushFrame(name, loc) {
|
|
89
79
|
advanceToPos(loc.start);
|
|
90
80
|
nameStack.unshift({
|
|
@@ -92,35 +82,28 @@ function forEachMapping(ast, context, pushMapping) {
|
|
|
92
82
|
loc,
|
|
93
83
|
});
|
|
94
84
|
}
|
|
95
|
-
|
|
96
85
|
function popFrame() {
|
|
97
86
|
const top = nameStack[0];
|
|
98
|
-
|
|
99
87
|
if (top) {
|
|
100
88
|
const { loc } = top;
|
|
101
89
|
advanceToPos(loc.end);
|
|
102
90
|
nameStack.shift();
|
|
103
91
|
}
|
|
104
92
|
}
|
|
105
|
-
|
|
106
93
|
if (!context) {
|
|
107
94
|
context = {};
|
|
108
95
|
}
|
|
109
|
-
|
|
110
96
|
const basename = context.filename
|
|
111
97
|
? fsPath.basename(context.filename).replace(/\..+$/, "")
|
|
112
98
|
: null;
|
|
113
99
|
const visitor = {
|
|
114
100
|
enter(path) {
|
|
115
101
|
let name = getNameForPath(path);
|
|
116
|
-
|
|
117
102
|
if (basename) {
|
|
118
103
|
name = removeNamePrefix(name, basename);
|
|
119
104
|
}
|
|
120
|
-
|
|
121
105
|
pushFrame(name, nullthrows(path.node.loc));
|
|
122
106
|
},
|
|
123
|
-
|
|
124
107
|
exit(path) {
|
|
125
108
|
popFrame();
|
|
126
109
|
},
|
|
@@ -131,49 +114,45 @@ function forEachMapping(ast, context, pushMapping) {
|
|
|
131
114
|
Class: visitor,
|
|
132
115
|
});
|
|
133
116
|
}
|
|
134
|
-
|
|
135
117
|
const ANONYMOUS_NAME = "<anonymous>";
|
|
118
|
+
|
|
136
119
|
/**
|
|
137
120
|
* Derive a contextual name for the given AST node (Function, Program, Class or
|
|
138
121
|
* ObjectExpression).
|
|
139
122
|
*/
|
|
140
|
-
|
|
141
123
|
function getNameForPath(path) {
|
|
142
124
|
const { node, parent, parentPath } = path;
|
|
143
|
-
|
|
144
125
|
if ((0, _types.isProgram)(node)) {
|
|
145
126
|
return "<global>";
|
|
146
127
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
128
|
+
let { id } = path;
|
|
129
|
+
// has an `id` so we don't need to infer one
|
|
150
130
|
if (node.id) {
|
|
151
131
|
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
152
132
|
return node.id.name;
|
|
153
133
|
}
|
|
154
|
-
|
|
155
134
|
let propertyPath;
|
|
156
|
-
let kind;
|
|
135
|
+
let kind;
|
|
157
136
|
|
|
137
|
+
// Find or construct an AST node that names the current node.
|
|
158
138
|
if ((0, _types.isObjectMethod)(node) || (0, _types.isClassMethod)(node)) {
|
|
159
139
|
// ({ foo() {} });
|
|
160
140
|
id = node.key;
|
|
161
|
-
|
|
162
141
|
if (node.kind !== "method" && node.kind !== "constructor") {
|
|
163
142
|
// Store the method's kind so we can add it to the final name.
|
|
164
143
|
kind = node.kind;
|
|
165
|
-
}
|
|
144
|
+
}
|
|
145
|
+
// Also store the path to the property so we can find its context
|
|
166
146
|
// (object/class) later and add _its_ name to the result.
|
|
167
|
-
|
|
168
147
|
propertyPath = path;
|
|
169
148
|
} else if (
|
|
170
149
|
(0, _types.isObjectProperty)(parent) ||
|
|
171
150
|
(0, _types.isClassProperty)(parent)
|
|
172
151
|
) {
|
|
173
152
|
// ({ foo: function() {} });
|
|
174
|
-
id = parent.key;
|
|
153
|
+
id = parent.key;
|
|
154
|
+
// Also store the path to the property so we can find its context
|
|
175
155
|
// (object/class) later and add _its_ name to the result.
|
|
176
|
-
|
|
177
156
|
propertyPath = parentPath;
|
|
178
157
|
} else if ((0, _types.isVariableDeclarator)(parent)) {
|
|
179
158
|
// let foo = function () {};
|
|
@@ -183,7 +162,6 @@ function getNameForPath(path) {
|
|
|
183
162
|
id = parent.left;
|
|
184
163
|
} else if ((0, _types.isJSXExpressionContainer)(parent)) {
|
|
185
164
|
var _parentPath$parentPat;
|
|
186
|
-
|
|
187
165
|
const grandParentNode =
|
|
188
166
|
parentPath === null || parentPath === void 0
|
|
189
167
|
? void 0
|
|
@@ -191,7 +169,6 @@ function getNameForPath(path) {
|
|
|
191
169
|
_parentPath$parentPat === void 0
|
|
192
170
|
? void 0
|
|
193
171
|
: _parentPath$parentPat.node;
|
|
194
|
-
|
|
195
172
|
if ((0, _types.isJSXElement)(grandParentNode)) {
|
|
196
173
|
// <foo>{function () {}}</foo>
|
|
197
174
|
const openingElement = grandParentNode.openingElement;
|
|
@@ -202,7 +179,6 @@ function getNameForPath(path) {
|
|
|
202
179
|
);
|
|
203
180
|
} else if ((0, _types.isJSXAttribute)(grandParentNode)) {
|
|
204
181
|
var _parentPath$parentPat2, _parentPath$parentPat3;
|
|
205
|
-
|
|
206
182
|
// <foo bar={function () {}} />
|
|
207
183
|
const openingElement =
|
|
208
184
|
parentPath === null || parentPath === void 0
|
|
@@ -217,79 +193,74 @@ function getNameForPath(path) {
|
|
|
217
193
|
const prop = grandParentNode;
|
|
218
194
|
id = t.jsxMemberExpression(
|
|
219
195
|
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
220
|
-
t.jsxMemberExpression(openingElement.name, t.jsxIdentifier("props")),
|
|
196
|
+
t.jsxMemberExpression(openingElement.name, t.jsxIdentifier("props")),
|
|
197
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
221
198
|
prop.name
|
|
222
199
|
);
|
|
223
200
|
}
|
|
224
|
-
}
|
|
201
|
+
}
|
|
225
202
|
|
|
203
|
+
// Collapse the name AST, if any, into a string.
|
|
226
204
|
let name = getNameFromId(id);
|
|
227
|
-
|
|
228
205
|
if (name == null) {
|
|
229
206
|
// We couldn't find a name directly. Try the parent in certain cases.
|
|
230
207
|
if (isAnyCallExpression(parent)) {
|
|
231
208
|
// foo(function () {})
|
|
232
209
|
const argIndex = parent.arguments.indexOf(node);
|
|
233
|
-
|
|
234
210
|
if (argIndex !== -1) {
|
|
235
|
-
const calleeName = getNameFromId(parent.callee);
|
|
236
|
-
|
|
211
|
+
const calleeName = getNameFromId(parent.callee);
|
|
212
|
+
// var f = Object.freeze(function () {})
|
|
237
213
|
if (argIndex === 0 && calleeName === "Object.freeze") {
|
|
238
214
|
return getNameForPath(nullthrows(parentPath));
|
|
239
|
-
}
|
|
240
|
-
|
|
215
|
+
}
|
|
216
|
+
// var f = useCallback(function () {})
|
|
241
217
|
if (
|
|
242
218
|
argIndex === 0 &&
|
|
243
219
|
(calleeName === "useCallback" || calleeName === "React.useCallback")
|
|
244
220
|
) {
|
|
245
221
|
return getNameForPath(nullthrows(parentPath));
|
|
246
222
|
}
|
|
247
|
-
|
|
248
223
|
if (calleeName) {
|
|
249
224
|
return `${calleeName}$argument_${argIndex}`;
|
|
250
225
|
}
|
|
251
226
|
}
|
|
252
227
|
}
|
|
253
|
-
|
|
254
228
|
if (
|
|
255
229
|
(0, _types.isTypeCastExpression)(parent) &&
|
|
256
230
|
parent.expression === node
|
|
257
231
|
) {
|
|
258
232
|
return getNameForPath(nullthrows(parentPath));
|
|
259
233
|
}
|
|
260
|
-
|
|
261
234
|
if ((0, _types.isExportDefaultDeclaration)(parent)) {
|
|
262
235
|
return "default";
|
|
263
|
-
}
|
|
264
|
-
|
|
236
|
+
}
|
|
237
|
+
// We couldn't infer a name at all.
|
|
265
238
|
return ANONYMOUS_NAME;
|
|
266
|
-
}
|
|
239
|
+
}
|
|
267
240
|
|
|
241
|
+
// Annotate getters and setters.
|
|
268
242
|
if (kind != null) {
|
|
269
243
|
name = kind + "__" + name;
|
|
270
|
-
}
|
|
244
|
+
}
|
|
271
245
|
|
|
246
|
+
// Annotate members with the name of their containing object/class.
|
|
272
247
|
if (propertyPath) {
|
|
273
248
|
if ((0, _types.isClassBody)(propertyPath.parent)) {
|
|
274
249
|
// $FlowFixMe Discovered when typing babel-traverse
|
|
275
250
|
const className = getNameForPath(propertyPath.parentPath.parentPath);
|
|
276
|
-
|
|
277
251
|
if (className !== ANONYMOUS_NAME) {
|
|
278
252
|
const separator = propertyPath.node.static ? "." : "#";
|
|
279
253
|
name = className + separator + name;
|
|
280
254
|
}
|
|
281
255
|
} else if ((0, _types.isObjectExpression)(propertyPath.parent)) {
|
|
282
256
|
const objectName = getNameForPath(nullthrows(propertyPath.parentPath));
|
|
283
|
-
|
|
284
257
|
if (objectName !== ANONYMOUS_NAME) {
|
|
285
258
|
name = objectName + "." + name;
|
|
286
259
|
}
|
|
287
260
|
}
|
|
288
261
|
}
|
|
289
|
-
|
|
290
262
|
return name;
|
|
291
263
|
}
|
|
292
|
-
|
|
293
264
|
function isAnyCallExpression(node) {
|
|
294
265
|
return (
|
|
295
266
|
node.type === "CallExpression" ||
|
|
@@ -297,7 +268,6 @@ function isAnyCallExpression(node) {
|
|
|
297
268
|
node.type === "OptionalCallExpression"
|
|
298
269
|
);
|
|
299
270
|
}
|
|
300
|
-
|
|
301
271
|
function isAnyMemberExpression(node) {
|
|
302
272
|
return (
|
|
303
273
|
node.type === "MemberExpression" ||
|
|
@@ -305,18 +275,14 @@ function isAnyMemberExpression(node) {
|
|
|
305
275
|
node.type === "OptionalMemberExpression"
|
|
306
276
|
);
|
|
307
277
|
}
|
|
308
|
-
|
|
309
278
|
function isAnyIdentifier(node) {
|
|
310
279
|
return (0, _types.isIdentifier)(node) || (0, _types.isJSXIdentifier)(node);
|
|
311
280
|
}
|
|
312
|
-
|
|
313
281
|
function getNameFromId(id) {
|
|
314
282
|
const parts = getNamePartsFromId(id);
|
|
315
|
-
|
|
316
283
|
if (!parts.length) {
|
|
317
284
|
return null;
|
|
318
285
|
}
|
|
319
|
-
|
|
320
286
|
if (parts.length > 5) {
|
|
321
287
|
return (
|
|
322
288
|
parts[0] +
|
|
@@ -328,32 +294,25 @@ function getNameFromId(id) {
|
|
|
328
294
|
parts[parts.length - 1]
|
|
329
295
|
);
|
|
330
296
|
}
|
|
331
|
-
|
|
332
297
|
return parts.join(".");
|
|
333
298
|
}
|
|
334
|
-
|
|
335
299
|
function getNamePartsFromId(id) {
|
|
336
300
|
if (!id) {
|
|
337
301
|
return [];
|
|
338
302
|
}
|
|
339
|
-
|
|
340
303
|
if (isAnyCallExpression(id)) {
|
|
341
304
|
return getNamePartsFromId(id.callee);
|
|
342
305
|
}
|
|
343
|
-
|
|
344
306
|
if ((0, _types.isTypeCastExpression)(id)) {
|
|
345
307
|
return getNamePartsFromId(id.expression);
|
|
346
308
|
}
|
|
347
|
-
|
|
348
309
|
let name;
|
|
349
|
-
|
|
350
310
|
if (isAnyIdentifier(id)) {
|
|
351
311
|
name = id.name;
|
|
352
312
|
} else if ((0, _types.isNullLiteral)(id)) {
|
|
353
313
|
name = "null";
|
|
354
314
|
} else if ((0, _types.isRegExpLiteral)(id)) {
|
|
355
315
|
var _id$flags;
|
|
356
|
-
|
|
357
316
|
name = `_${id.pattern}_${
|
|
358
317
|
(_id$flags = id.flags) !== null && _id$flags !== void 0 ? _id$flags : ""
|
|
359
318
|
}`;
|
|
@@ -362,19 +321,15 @@ function getNamePartsFromId(id) {
|
|
|
362
321
|
} else if ((0, _types.isLiteral)(id) && id.value != null) {
|
|
363
322
|
name = String(id.value);
|
|
364
323
|
}
|
|
365
|
-
|
|
366
324
|
if (name != null) {
|
|
367
325
|
return [t.toBindingIdentifierName(name)];
|
|
368
326
|
}
|
|
369
|
-
|
|
370
327
|
if ((0, _types.isImport)(id)) {
|
|
371
328
|
name = "import";
|
|
372
329
|
}
|
|
373
|
-
|
|
374
330
|
if (name != null) {
|
|
375
331
|
return [name];
|
|
376
332
|
}
|
|
377
|
-
|
|
378
333
|
if (isAnyMemberExpression(id)) {
|
|
379
334
|
if (
|
|
380
335
|
isAnyIdentifier(id.object) &&
|
|
@@ -382,16 +337,13 @@ function getNamePartsFromId(id) {
|
|
|
382
337
|
(isAnyIdentifier(id.property) || (0, _types.isLiteral)(id.property))
|
|
383
338
|
) {
|
|
384
339
|
const propertyName = getNameFromId(id.property);
|
|
385
|
-
|
|
386
340
|
if (propertyName) {
|
|
387
341
|
name = "@@" + propertyName;
|
|
388
342
|
}
|
|
389
343
|
} else {
|
|
390
344
|
const propertyName = getNamePartsFromId(id.property);
|
|
391
|
-
|
|
392
345
|
if (propertyName.length) {
|
|
393
346
|
const objectName = getNamePartsFromId(id.object);
|
|
394
|
-
|
|
395
347
|
if (objectName.length) {
|
|
396
348
|
return [...objectName, ...propertyName];
|
|
397
349
|
} else {
|
|
@@ -400,31 +352,27 @@ function getNamePartsFromId(id) {
|
|
|
400
352
|
}
|
|
401
353
|
}
|
|
402
354
|
}
|
|
403
|
-
|
|
404
355
|
return name ? [name] : [];
|
|
405
356
|
}
|
|
406
|
-
|
|
407
357
|
const DELIMITER_START_RE = /^[^A-Za-z0-9_$@]+/;
|
|
358
|
+
|
|
408
359
|
/**
|
|
409
360
|
* Strip the given prefix from `name`, if it occurs there, plus any delimiter
|
|
410
361
|
* characters that follow (of which at least one is required). If an empty
|
|
411
362
|
* string would be returned, return the original name instead.
|
|
412
363
|
*/
|
|
413
|
-
|
|
414
364
|
function removeNamePrefix(name, namePrefix) {
|
|
415
365
|
if (!namePrefix.length || !name.startsWith(namePrefix)) {
|
|
416
366
|
return name;
|
|
417
367
|
}
|
|
418
|
-
|
|
419
368
|
const shortenedName = name.substr(namePrefix.length);
|
|
420
369
|
const [delimiterMatch] = shortenedName.match(DELIMITER_START_RE) || [];
|
|
421
|
-
|
|
422
370
|
if (delimiterMatch) {
|
|
423
371
|
return shortenedName.substr(delimiterMatch.length) || name;
|
|
424
372
|
}
|
|
425
|
-
|
|
426
373
|
return name;
|
|
427
374
|
}
|
|
375
|
+
|
|
428
376
|
/**
|
|
429
377
|
* Encodes function name mappings as deltas in a Base64 VLQ format inspired by
|
|
430
378
|
* the standard source map format.
|
|
@@ -449,7 +397,6 @@ function removeNamePrefix(name, namePrefix) {
|
|
|
449
397
|
* Lines and columns are both 0-based in the serialised format. In memory,
|
|
450
398
|
* lines are 1-based while columns are 0-based.
|
|
451
399
|
*/
|
|
452
|
-
|
|
453
400
|
class MappingEncoder {
|
|
454
401
|
constructor() {
|
|
455
402
|
this._namesMap = new Map();
|
|
@@ -459,65 +406,49 @@ class MappingEncoder {
|
|
|
459
406
|
this._nameIndex = new RelativeValue(0);
|
|
460
407
|
this._mappings = new B64Builder();
|
|
461
408
|
}
|
|
462
|
-
|
|
463
409
|
getResult() {
|
|
464
410
|
return {
|
|
465
411
|
names: this._names,
|
|
466
412
|
mappings: this._mappings.toString(),
|
|
467
413
|
};
|
|
468
414
|
}
|
|
469
|
-
|
|
470
415
|
push({ name, start }) {
|
|
471
416
|
let nameIndex = this._namesMap.get(name);
|
|
472
|
-
|
|
473
417
|
if (typeof nameIndex !== "number") {
|
|
474
418
|
nameIndex = this._names.length;
|
|
475
419
|
this._names[nameIndex] = name;
|
|
476
|
-
|
|
477
420
|
this._namesMap.set(name, nameIndex);
|
|
478
421
|
}
|
|
479
|
-
|
|
480
422
|
const lineDelta = this._line.next(start.line);
|
|
481
|
-
|
|
482
423
|
const firstOfLine = this._mappings.pos === 0 || lineDelta > 0;
|
|
483
|
-
|
|
484
424
|
if (lineDelta > 0) {
|
|
485
425
|
// The next entry will have the line offset, so emit just one semicolon.
|
|
486
426
|
this._mappings.markLines(1);
|
|
487
|
-
|
|
488
427
|
this._column.reset(0);
|
|
489
428
|
}
|
|
490
|
-
|
|
491
429
|
this._mappings.startSegment(this._column.next(start.column));
|
|
492
|
-
|
|
493
430
|
this._mappings.append(this._nameIndex.next(nameIndex));
|
|
494
|
-
|
|
495
431
|
if (firstOfLine) {
|
|
496
432
|
this._mappings.append(lineDelta);
|
|
497
433
|
}
|
|
498
434
|
}
|
|
499
435
|
}
|
|
500
|
-
|
|
501
436
|
class RelativeValue {
|
|
502
437
|
constructor(value = 0) {
|
|
503
438
|
this.reset(value);
|
|
504
439
|
}
|
|
505
|
-
|
|
506
440
|
next(absoluteValue) {
|
|
507
441
|
const delta = absoluteValue - this._value;
|
|
508
442
|
this._value = absoluteValue;
|
|
509
443
|
return delta;
|
|
510
444
|
}
|
|
511
|
-
|
|
512
445
|
reset(value = 0) {
|
|
513
446
|
this._value = value;
|
|
514
447
|
}
|
|
515
448
|
}
|
|
516
|
-
|
|
517
449
|
function positionGreater(x, y) {
|
|
518
450
|
return x.line > y.line || (x.line === y.line && x.column > y.column);
|
|
519
451
|
}
|
|
520
|
-
|
|
521
452
|
module.exports = {
|
|
522
453
|
generateFunctionMap,
|
|
523
454
|
generateFunctionMappingsArray,
|
|
@@ -100,7 +100,7 @@ function forEachMapping(
|
|
|
100
100
|
context: ?Context,
|
|
101
101
|
pushMapping: RangeMapping => void,
|
|
102
102
|
) {
|
|
103
|
-
const nameStack = [];
|
|
103
|
+
const nameStack: Array<{loc: BabelNodeSourceLocation, name: string}> = [];
|
|
104
104
|
let tailPos = {line: 1, column: 0};
|
|
105
105
|
let tailName = null;
|
|
106
106
|
|
package/src/source-map.js
CHANGED
|
@@ -8,35 +8,27 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
|
+
|
|
11
12
|
"use strict";
|
|
12
13
|
|
|
13
14
|
const { BundleBuilder, createIndexMap } = require("./BundleBuilder");
|
|
14
|
-
|
|
15
15
|
const composeSourceMaps = require("./composeSourceMaps");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const Consumer = require("./Consumer");
|
|
17
|
+
// We need to export this for `metro-symbolicate`
|
|
19
18
|
const normalizeSourcePath = require("./Consumer/normalizeSourcePath");
|
|
20
|
-
|
|
21
19
|
const { generateFunctionMap } = require("./generateFunctionMap");
|
|
22
|
-
|
|
23
20
|
const Generator = require("./Generator");
|
|
24
|
-
|
|
25
21
|
const SourceMap = require("source-map");
|
|
26
|
-
|
|
27
22
|
function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
|
|
28
23
|
const modulesToProcess = modules.slice();
|
|
29
24
|
const generator = new Generator();
|
|
30
25
|
let carryOver = offsetLines;
|
|
31
|
-
|
|
32
26
|
function processNextModule() {
|
|
33
27
|
if (modulesToProcess.length === 0) {
|
|
34
28
|
return true;
|
|
35
29
|
}
|
|
36
|
-
|
|
37
30
|
const mod = modulesToProcess.shift();
|
|
38
31
|
const { code, map } = mod;
|
|
39
|
-
|
|
40
32
|
if (Array.isArray(map)) {
|
|
41
33
|
addMappingsForFile(generator, map, mod, carryOver);
|
|
42
34
|
} else if (map != null) {
|
|
@@ -44,28 +36,22 @@ function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
|
|
|
44
36
|
`Unexpected module with full source map found: ${mod.path}`
|
|
45
37
|
);
|
|
46
38
|
}
|
|
47
|
-
|
|
48
39
|
carryOver = carryOver + countLines(code);
|
|
49
40
|
return false;
|
|
50
41
|
}
|
|
51
|
-
|
|
52
42
|
function workLoop() {
|
|
53
43
|
const time = process.hrtime();
|
|
54
|
-
|
|
55
44
|
while (true) {
|
|
56
45
|
const isDone = processNextModule();
|
|
57
|
-
|
|
58
46
|
if (isDone) {
|
|
59
47
|
onDone(generator);
|
|
60
48
|
break;
|
|
61
49
|
}
|
|
62
|
-
|
|
63
50
|
if (!isBlocking) {
|
|
64
51
|
// Keep the loop running but try to avoid blocking
|
|
65
52
|
// for too long because this is not in a worker yet.
|
|
66
53
|
const diff = process.hrtime(time);
|
|
67
54
|
const NS_IN_MS = 1000000;
|
|
68
|
-
|
|
69
55
|
if (diff[1] > 50 * NS_IN_MS) {
|
|
70
56
|
// We've blocked for more than 50ms.
|
|
71
57
|
// This code currently runs on the main thread,
|
|
@@ -76,9 +62,9 @@ function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
|
|
|
76
62
|
}
|
|
77
63
|
}
|
|
78
64
|
}
|
|
79
|
-
|
|
80
65
|
workLoop();
|
|
81
66
|
}
|
|
67
|
+
|
|
82
68
|
/**
|
|
83
69
|
* Creates a source map from modules with "raw mappings", i.e. an array of
|
|
84
70
|
* tuples with either 2, 4, or 5 elements:
|
|
@@ -86,7 +72,6 @@ function fromRawMappingsImpl(isBlocking, onDone, modules, offsetLines) {
|
|
|
86
72
|
* Accepts an `offsetLines` argument in case modules' code is to be offset in
|
|
87
73
|
* the resulting bundle, e.g. by some prefix code.
|
|
88
74
|
*/
|
|
89
|
-
|
|
90
75
|
function fromRawMappings(modules, offsetLines = 0) {
|
|
91
76
|
let generator;
|
|
92
77
|
fromRawMappingsImpl(
|
|
@@ -97,24 +82,21 @@ function fromRawMappings(modules, offsetLines = 0) {
|
|
|
97
82
|
modules,
|
|
98
83
|
offsetLines
|
|
99
84
|
);
|
|
100
|
-
|
|
101
85
|
if (generator == null) {
|
|
102
86
|
throw new Error("Expected fromRawMappingsImpl() to finish synchronously.");
|
|
103
87
|
}
|
|
104
|
-
|
|
105
88
|
return generator;
|
|
106
89
|
}
|
|
107
|
-
|
|
108
90
|
async function fromRawMappingsNonBlocking(modules, offsetLines = 0) {
|
|
109
91
|
return new Promise((resolve) => {
|
|
110
92
|
fromRawMappingsImpl(false, resolve, modules, offsetLines);
|
|
111
93
|
});
|
|
112
94
|
}
|
|
95
|
+
|
|
113
96
|
/**
|
|
114
97
|
* Transforms a standard source map object into a Raw Mappings object, to be
|
|
115
98
|
* used across the bundler.
|
|
116
99
|
*/
|
|
117
|
-
|
|
118
100
|
function toBabelSegments(sourceMap) {
|
|
119
101
|
const rawMappings = [];
|
|
120
102
|
new SourceMap.SourceMapConsumer(sourceMap).eachMapping((map) => {
|
|
@@ -133,38 +115,29 @@ function toBabelSegments(sourceMap) {
|
|
|
133
115
|
});
|
|
134
116
|
return rawMappings;
|
|
135
117
|
}
|
|
136
|
-
|
|
137
118
|
function toSegmentTuple(mapping) {
|
|
138
119
|
const { column, line } = mapping.generated;
|
|
139
120
|
const { name, original } = mapping;
|
|
140
|
-
|
|
141
121
|
if (original == null) {
|
|
142
122
|
return [line, column];
|
|
143
123
|
}
|
|
144
|
-
|
|
145
124
|
if (typeof name !== "string") {
|
|
146
125
|
return [line, column, original.line, original.column];
|
|
147
126
|
}
|
|
148
|
-
|
|
149
127
|
return [line, column, original.line, original.column, name];
|
|
150
128
|
}
|
|
151
|
-
|
|
152
129
|
function addMappingsForFile(generator, mappings, module, carryOver) {
|
|
153
130
|
generator.startFile(module.path, module.source, module.functionMap);
|
|
154
|
-
|
|
155
131
|
for (let i = 0, n = mappings.length; i < n; ++i) {
|
|
156
132
|
addMapping(generator, mappings[i], carryOver);
|
|
157
133
|
}
|
|
158
|
-
|
|
159
134
|
generator.endFile();
|
|
160
135
|
}
|
|
161
|
-
|
|
162
136
|
function addMapping(generator, mapping, carryOver) {
|
|
163
137
|
const n = mapping.length;
|
|
164
|
-
const line = mapping[0] + carryOver;
|
|
165
|
-
|
|
138
|
+
const line = mapping[0] + carryOver;
|
|
139
|
+
// lines start at 1, columns start at 0
|
|
166
140
|
const column = mapping[1];
|
|
167
|
-
|
|
168
141
|
if (n === 2) {
|
|
169
142
|
generator.addSimpleMapping(line, column);
|
|
170
143
|
} else if (n === 4) {
|
|
@@ -183,11 +156,8 @@ function addMapping(generator, mapping, carryOver) {
|
|
|
183
156
|
throw new Error(`Invalid mapping: [${mapping.join(", ")}]`);
|
|
184
157
|
}
|
|
185
158
|
}
|
|
186
|
-
|
|
187
159
|
const newline = /\r\n?|\n|\u2028|\u2029/g;
|
|
188
|
-
|
|
189
160
|
const countLines = (string) => (string.match(newline) || []).length + 1;
|
|
190
|
-
|
|
191
161
|
module.exports = {
|
|
192
162
|
BundleBuilder,
|
|
193
163
|
composeSourceMaps,
|
package/src/source-map.js.flow
CHANGED
|
@@ -203,7 +203,7 @@ async function fromRawMappingsNonBlocking(
|
|
|
203
203
|
function toBabelSegments(
|
|
204
204
|
sourceMap: BasicSourceMap,
|
|
205
205
|
): Array<BabelSourceMapSegment> {
|
|
206
|
-
const rawMappings = [];
|
|
206
|
+
const rawMappings: Array<BabelSourceMapSegment> = [];
|
|
207
207
|
|
|
208
208
|
new SourceMap.SourceMapConsumer(sourceMap).eachMapping(map => {
|
|
209
209
|
rawMappings.push({
|