metro-source-map 0.60.0 → 0.64.0
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
|
-
"version": "0.60.0",
|
|
3
2
|
"name": "metro-source-map",
|
|
3
|
+
"version": "0.64.0",
|
|
4
4
|
"description": "🚇 Source map generator for Metro.",
|
|
5
5
|
"main": "src/source-map.js",
|
|
6
6
|
"repository": {
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
"@babel/traverse": "^7.0.0",
|
|
16
16
|
"@babel/types": "^7.0.0",
|
|
17
17
|
"invariant": "^2.2.4",
|
|
18
|
-
"metro-symbolicate": "0.
|
|
19
|
-
"
|
|
18
|
+
"metro-symbolicate": "0.64.0",
|
|
19
|
+
"nullthrows": "^1.1.1",
|
|
20
|
+
"ob1": "0.64.0",
|
|
20
21
|
"source-map": "^0.5.6",
|
|
21
22
|
"vlq": "^1.0.0"
|
|
22
23
|
},
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
|
13
13
|
|
|
14
|
+
var _types = require("@babel/types");
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) {
|
|
15
17
|
return obj && obj.__esModule
|
|
16
18
|
? obj
|
|
@@ -116,6 +118,8 @@ const B64Builder = require("./B64Builder");
|
|
|
116
118
|
|
|
117
119
|
const fsPath = require("path");
|
|
118
120
|
|
|
121
|
+
const nullthrows = require("nullthrows");
|
|
122
|
+
|
|
119
123
|
const t = require("@babel/types");
|
|
120
124
|
/**
|
|
121
125
|
* Generate a map of source positions to function names. The names are meant to
|
|
@@ -202,22 +206,25 @@ function forEachMapping(ast, context, pushMapping) {
|
|
|
202
206
|
const basename = context.filename
|
|
203
207
|
? fsPath.basename(context.filename).replace(/\..+$/, "")
|
|
204
208
|
: null;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
let name = getNameForPath(path);
|
|
209
|
+
const visitor = {
|
|
210
|
+
enter(path) {
|
|
211
|
+
let name = getNameForPath(path);
|
|
209
212
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
if (basename) {
|
|
214
|
+
name = removeNamePrefix(name, basename);
|
|
215
|
+
}
|
|
213
216
|
|
|
214
|
-
|
|
215
|
-
|
|
217
|
+
pushFrame(name, nullthrows(path.node.loc));
|
|
218
|
+
},
|
|
216
219
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
+
exit(path) {
|
|
221
|
+
popFrame();
|
|
220
222
|
}
|
|
223
|
+
};
|
|
224
|
+
(0, _traverse.default)(ast, {
|
|
225
|
+
Function: visitor,
|
|
226
|
+
Program: visitor,
|
|
227
|
+
Class: visitor
|
|
221
228
|
});
|
|
222
229
|
}
|
|
223
230
|
|
|
@@ -233,20 +240,22 @@ function getNameForPath(path) {
|
|
|
233
240
|
parent = path.parent,
|
|
234
241
|
parentPath = path.parentPath;
|
|
235
242
|
|
|
236
|
-
if (
|
|
243
|
+
if ((0, _types.isProgram)(node)) {
|
|
237
244
|
return "<global>";
|
|
238
245
|
}
|
|
239
246
|
|
|
240
|
-
let
|
|
247
|
+
let _ref = path,
|
|
248
|
+
id = _ref.id; // has an `id` so we don't need to infer one
|
|
241
249
|
|
|
242
250
|
if (node.id) {
|
|
251
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
243
252
|
return node.id.name;
|
|
244
253
|
}
|
|
245
254
|
|
|
246
255
|
let propertyPath;
|
|
247
256
|
let kind = "";
|
|
248
257
|
|
|
249
|
-
if (
|
|
258
|
+
if ((0, _types.isObjectMethod)(node) || (0, _types.isClassMethod)(node)) {
|
|
250
259
|
id = node.key;
|
|
251
260
|
|
|
252
261
|
if (node.kind !== "method" && node.kind !== "constructor") {
|
|
@@ -254,30 +263,55 @@ function getNameForPath(path) {
|
|
|
254
263
|
}
|
|
255
264
|
|
|
256
265
|
propertyPath = path;
|
|
257
|
-
} else if (
|
|
266
|
+
} else if (
|
|
267
|
+
(0, _types.isObjectProperty)(parent) ||
|
|
268
|
+
(0, _types.isClassProperty)(parent)
|
|
269
|
+
) {
|
|
258
270
|
// { foo() {} };
|
|
259
271
|
id = parent.key;
|
|
260
272
|
propertyPath = parentPath;
|
|
261
|
-
} else if (
|
|
273
|
+
} else if ((0, _types.isVariableDeclarator)(parent)) {
|
|
262
274
|
// let foo = function () {};
|
|
263
275
|
id = parent.id;
|
|
264
|
-
} else if (
|
|
276
|
+
} else if ((0, _types.isAssignmentExpression)(parent)) {
|
|
265
277
|
// foo = function () {};
|
|
266
278
|
id = parent.left;
|
|
267
|
-
} else if (
|
|
268
|
-
|
|
279
|
+
} else if ((0, _types.isJSXExpressionContainer)(parent)) {
|
|
280
|
+
var _parentPath$parentPat;
|
|
281
|
+
|
|
282
|
+
const grandParentNode =
|
|
283
|
+
parentPath === null || parentPath === void 0
|
|
284
|
+
? void 0
|
|
285
|
+
: (_parentPath$parentPat = parentPath.parentPath) === null ||
|
|
286
|
+
_parentPath$parentPat === void 0
|
|
287
|
+
? void 0
|
|
288
|
+
: _parentPath$parentPat.node;
|
|
289
|
+
|
|
290
|
+
if ((0, _types.isJSXElement)(grandParentNode)) {
|
|
269
291
|
// <foo>{function () {}}</foo>
|
|
270
|
-
const openingElement =
|
|
271
|
-
id = t.
|
|
272
|
-
|
|
273
|
-
t.
|
|
292
|
+
const openingElement = grandParentNode.openingElement;
|
|
293
|
+
id = t.jsxMemberExpression(
|
|
294
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
295
|
+
t.jsxMemberExpression(openingElement.name, t.jsxIdentifier("props")),
|
|
296
|
+
t.jsxIdentifier("children")
|
|
274
297
|
);
|
|
275
|
-
} else if (
|
|
276
|
-
// <foo bar={function () {}} />
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
298
|
+
} else if ((0, _types.isJSXAttribute)(grandParentNode)) {
|
|
299
|
+
var _parentPath$parentPat2, _parentPath$parentPat3; // <foo bar={function () {}} />
|
|
300
|
+
|
|
301
|
+
const openingElement =
|
|
302
|
+
parentPath === null || parentPath === void 0
|
|
303
|
+
? void 0
|
|
304
|
+
: (_parentPath$parentPat2 = parentPath.parentPath) === null ||
|
|
305
|
+
_parentPath$parentPat2 === void 0
|
|
306
|
+
? void 0
|
|
307
|
+
: (_parentPath$parentPat3 = _parentPath$parentPat2.parentPath) ===
|
|
308
|
+
null || _parentPath$parentPat3 === void 0
|
|
309
|
+
? void 0
|
|
310
|
+
: _parentPath$parentPat3.node;
|
|
311
|
+
const prop = grandParentNode;
|
|
312
|
+
id = t.jsxMemberExpression(
|
|
313
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
314
|
+
t.jsxMemberExpression(openingElement.name, t.jsxIdentifier("props")), // $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
281
315
|
prop.name
|
|
282
316
|
);
|
|
283
317
|
}
|
|
@@ -286,7 +320,10 @@ function getNameForPath(path) {
|
|
|
286
320
|
let name = getNameFromId(id);
|
|
287
321
|
|
|
288
322
|
if (name == null) {
|
|
289
|
-
if (
|
|
323
|
+
if (
|
|
324
|
+
(0, _types.isCallExpression)(parent) ||
|
|
325
|
+
(0, _types.isNewExpression)(parent)
|
|
326
|
+
) {
|
|
290
327
|
// foo(function () {})
|
|
291
328
|
const argIndex = parent.arguments.indexOf(node);
|
|
292
329
|
|
|
@@ -294,7 +331,7 @@ function getNameForPath(path) {
|
|
|
294
331
|
const calleeName = getNameFromId(parent.callee); // var f = Object.freeze(function () {})
|
|
295
332
|
|
|
296
333
|
if (CALLEES_TO_SKIP.indexOf(calleeName) !== -1) {
|
|
297
|
-
return getNameForPath(parentPath);
|
|
334
|
+
return getNameForPath(nullthrows(parentPath));
|
|
298
335
|
}
|
|
299
336
|
|
|
300
337
|
if (calleeName) {
|
|
@@ -303,6 +340,13 @@ function getNameForPath(path) {
|
|
|
303
340
|
}
|
|
304
341
|
}
|
|
305
342
|
|
|
343
|
+
if (
|
|
344
|
+
(0, _types.isTypeCastExpression)(parent) &&
|
|
345
|
+
parent.expression === node
|
|
346
|
+
) {
|
|
347
|
+
return getNameForPath(nullthrows(parentPath));
|
|
348
|
+
}
|
|
349
|
+
|
|
306
350
|
return ANONYMOUS_NAME;
|
|
307
351
|
}
|
|
308
352
|
|
|
@@ -311,15 +355,17 @@ function getNameForPath(path) {
|
|
|
311
355
|
}
|
|
312
356
|
|
|
313
357
|
if (propertyPath) {
|
|
314
|
-
if (
|
|
358
|
+
if ((0, _types.isClassBody)(propertyPath.parent)) {
|
|
359
|
+
// $FlowFixMe Disvoered when typing babel-traverse
|
|
315
360
|
const className = getNameForPath(propertyPath.parentPath.parentPath);
|
|
316
361
|
|
|
317
362
|
if (className !== ANONYMOUS_NAME) {
|
|
363
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
318
364
|
const separator = propertyPath.node.static ? "." : "#";
|
|
319
365
|
name = className + separator + name;
|
|
320
366
|
}
|
|
321
|
-
} else if (
|
|
322
|
-
const objectName = getNameForPath(propertyPath.parentPath);
|
|
367
|
+
} else if ((0, _types.isObjectExpression)(propertyPath.parent)) {
|
|
368
|
+
const objectName = getNameForPath(nullthrows(propertyPath.parentPath));
|
|
323
369
|
|
|
324
370
|
if (objectName !== ANONYMOUS_NAME) {
|
|
325
371
|
name = objectName + "." + name;
|
|
@@ -331,11 +377,13 @@ function getNameForPath(path) {
|
|
|
331
377
|
}
|
|
332
378
|
|
|
333
379
|
function isAnyMemberExpression(node) {
|
|
334
|
-
return
|
|
380
|
+
return (
|
|
381
|
+
node.type === "MemberExpression" || node.type === "JSXMemberExpression"
|
|
382
|
+
);
|
|
335
383
|
}
|
|
336
384
|
|
|
337
385
|
function isAnyIdentifier(node) {
|
|
338
|
-
return
|
|
386
|
+
return (0, _types.isIdentifier)(node) || (0, _types.isJSXIdentifier)(node);
|
|
339
387
|
}
|
|
340
388
|
|
|
341
389
|
function getNameFromId(id) {
|
|
@@ -365,11 +413,11 @@ function getNamePartsFromId(id) {
|
|
|
365
413
|
return [];
|
|
366
414
|
}
|
|
367
415
|
|
|
368
|
-
if (
|
|
416
|
+
if ((0, _types.isCallExpression)(id) || (0, _types.isNewExpression)(id)) {
|
|
369
417
|
return getNamePartsFromId(id.callee);
|
|
370
418
|
}
|
|
371
419
|
|
|
372
|
-
if (
|
|
420
|
+
if ((0, _types.isTypeCastExpression)(id)) {
|
|
373
421
|
return getNamePartsFromId(id.expression);
|
|
374
422
|
}
|
|
375
423
|
|
|
@@ -377,21 +425,25 @@ function getNamePartsFromId(id) {
|
|
|
377
425
|
|
|
378
426
|
if (isAnyIdentifier(id)) {
|
|
379
427
|
name = id.name;
|
|
380
|
-
} else if (
|
|
428
|
+
} else if ((0, _types.isNullLiteral)(id)) {
|
|
381
429
|
name = "null";
|
|
382
|
-
} else if (
|
|
383
|
-
|
|
384
|
-
|
|
430
|
+
} else if ((0, _types.isRegExpLiteral)(id)) {
|
|
431
|
+
var _id$flags;
|
|
432
|
+
|
|
433
|
+
name = `_${id.pattern}_${
|
|
434
|
+
(_id$flags = id.flags) !== null && _id$flags !== void 0 ? _id$flags : ""
|
|
435
|
+
}`;
|
|
436
|
+
} else if ((0, _types.isTemplateLiteral)(id)) {
|
|
385
437
|
name = id.quasis.map(quasi => quasi.value.raw).join("");
|
|
386
|
-
} else if (
|
|
387
|
-
name = id.value
|
|
438
|
+
} else if ((0, _types.isLiteral)(id) && id.value != null) {
|
|
439
|
+
name = String(id.value);
|
|
388
440
|
}
|
|
389
441
|
|
|
390
442
|
if (name != null) {
|
|
391
443
|
return [t.toBindingIdentifierName(name)];
|
|
392
444
|
}
|
|
393
445
|
|
|
394
|
-
if (
|
|
446
|
+
if ((0, _types.isImport)(id)) {
|
|
395
447
|
name = "import";
|
|
396
448
|
}
|
|
397
449
|
|
|
@@ -403,7 +455,7 @@ function getNamePartsFromId(id) {
|
|
|
403
455
|
if (
|
|
404
456
|
isAnyIdentifier(id.object) &&
|
|
405
457
|
id.object.name === "Symbol" &&
|
|
406
|
-
(isAnyIdentifier(id.property) ||
|
|
458
|
+
(isAnyIdentifier(id.property) || (0, _types.isLiteral)(id.property))
|
|
407
459
|
) {
|
|
408
460
|
const propertyName = getNameFromId(id.property);
|
|
409
461
|
|
|
@@ -445,9 +497,9 @@ function removeNamePrefix(name, namePrefix) {
|
|
|
445
497
|
|
|
446
498
|
const shortenedName = name.substr(namePrefix.length);
|
|
447
499
|
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
delimiterMatch =
|
|
500
|
+
const _ref2 = shortenedName.match(DELIMITER_START_RE) || [],
|
|
501
|
+
_ref3 = _slicedToArray(_ref2, 1),
|
|
502
|
+
delimiterMatch = _ref3[0];
|
|
451
503
|
|
|
452
504
|
if (delimiterMatch) {
|
|
453
505
|
return shortenedName.substr(delimiterMatch.length) || name;
|
|
@@ -497,9 +549,9 @@ class MappingEncoder {
|
|
|
497
549
|
};
|
|
498
550
|
}
|
|
499
551
|
|
|
500
|
-
push(
|
|
501
|
-
let name =
|
|
502
|
-
start =
|
|
552
|
+
push(_ref4) {
|
|
553
|
+
let name = _ref4.name,
|
|
554
|
+
start = _ref4.start;
|
|
503
555
|
|
|
504
556
|
let nameIndex = this._namesMap.get(name);
|
|
505
557
|
|
|
@@ -13,12 +13,38 @@
|
|
|
13
13
|
const B64Builder = require('./B64Builder');
|
|
14
14
|
|
|
15
15
|
const fsPath = require('path');
|
|
16
|
+
const nullthrows = require('nullthrows');
|
|
16
17
|
const t = require('@babel/types');
|
|
17
18
|
|
|
18
19
|
import type {FBSourceFunctionMap} from './source-map';
|
|
19
|
-
import type {Ast} from '@babel/core';
|
|
20
20
|
import traverse from '@babel/traverse';
|
|
21
|
-
import type {
|
|
21
|
+
import type {NodePath} from '@babel/traverse';
|
|
22
|
+
import {
|
|
23
|
+
isProgram,
|
|
24
|
+
isIdentifier,
|
|
25
|
+
isJSXIdentifier,
|
|
26
|
+
isCallExpression,
|
|
27
|
+
isNewExpression,
|
|
28
|
+
isTypeCastExpression,
|
|
29
|
+
isRegExpLiteral,
|
|
30
|
+
isTemplateLiteral,
|
|
31
|
+
isLiteral,
|
|
32
|
+
isObjectMethod,
|
|
33
|
+
isClassMethod,
|
|
34
|
+
isObjectProperty,
|
|
35
|
+
isClassProperty,
|
|
36
|
+
isVariableDeclarator,
|
|
37
|
+
isAssignmentExpression,
|
|
38
|
+
isJSXExpressionContainer,
|
|
39
|
+
isJSXElement,
|
|
40
|
+
isJSXAttribute,
|
|
41
|
+
isNullLiteral,
|
|
42
|
+
isImport,
|
|
43
|
+
isClassBody,
|
|
44
|
+
isObjectExpression,
|
|
45
|
+
} from '@babel/types';
|
|
46
|
+
import type {Node} from '@babel/types';
|
|
47
|
+
|
|
22
48
|
type Position = {
|
|
23
49
|
line: number,
|
|
24
50
|
column: number,
|
|
@@ -39,7 +65,10 @@ type Context = {filename?: string, ...};
|
|
|
39
65
|
* The output is encoded for use in a source map. For details about the format,
|
|
40
66
|
* see MappingEncoder below.
|
|
41
67
|
*/
|
|
42
|
-
function generateFunctionMap(
|
|
68
|
+
function generateFunctionMap(
|
|
69
|
+
ast: BabelNode,
|
|
70
|
+
context?: Context,
|
|
71
|
+
): FBSourceFunctionMap {
|
|
43
72
|
const encoder = new MappingEncoder();
|
|
44
73
|
forEachMapping(ast, context, mapping => encoder.push(mapping));
|
|
45
74
|
return encoder.getResult();
|
|
@@ -52,7 +81,7 @@ function generateFunctionMap(ast: Ast, context?: Context): FBSourceFunctionMap {
|
|
|
52
81
|
* Lines are 1-based and columns are 0-based.
|
|
53
82
|
*/
|
|
54
83
|
function generateFunctionMappingsArray(
|
|
55
|
-
ast:
|
|
84
|
+
ast: BabelNode,
|
|
56
85
|
context?: Context,
|
|
57
86
|
): $ReadOnlyArray<RangeMapping> {
|
|
58
87
|
const mappings = [];
|
|
@@ -67,7 +96,7 @@ function generateFunctionMappingsArray(
|
|
|
67
96
|
* mappings, one at a time.
|
|
68
97
|
*/
|
|
69
98
|
function forEachMapping(
|
|
70
|
-
ast:
|
|
99
|
+
ast: BabelNode,
|
|
71
100
|
context: ?Context,
|
|
72
101
|
pushMapping: RangeMapping => void,
|
|
73
102
|
) {
|
|
@@ -89,7 +118,7 @@ function forEachMapping(
|
|
|
89
118
|
tailPos = pos;
|
|
90
119
|
}
|
|
91
120
|
|
|
92
|
-
function pushFrame(name, loc) {
|
|
121
|
+
function pushFrame(name: string, loc: BabelNodeSourceLocation) {
|
|
93
122
|
advanceToPos(loc.start);
|
|
94
123
|
nameStack.unshift({name, loc});
|
|
95
124
|
}
|
|
@@ -111,19 +140,25 @@ function forEachMapping(
|
|
|
111
140
|
? fsPath.basename(context.filename).replace(/\..+$/, '')
|
|
112
141
|
: null;
|
|
113
142
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
},
|
|
123
|
-
exit(path) {
|
|
124
|
-
popFrame();
|
|
125
|
-
},
|
|
143
|
+
const visitor = {
|
|
144
|
+
enter(path) {
|
|
145
|
+
let name = getNameForPath(path);
|
|
146
|
+
if (basename) {
|
|
147
|
+
name = removeNamePrefix(name, basename);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
pushFrame(name, nullthrows(path.node.loc));
|
|
126
151
|
},
|
|
152
|
+
|
|
153
|
+
exit(path): void {
|
|
154
|
+
popFrame();
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
traverse(ast, {
|
|
159
|
+
Function: visitor,
|
|
160
|
+
Program: visitor,
|
|
161
|
+
Class: visitor,
|
|
127
162
|
});
|
|
128
163
|
}
|
|
129
164
|
|
|
@@ -134,48 +169,54 @@ const CALLEES_TO_SKIP = ['Object.freeze'];
|
|
|
134
169
|
* Derive a contextual name for the given AST node (Function, Program, Class or
|
|
135
170
|
* ObjectExpression).
|
|
136
171
|
*/
|
|
137
|
-
function getNameForPath(path:
|
|
172
|
+
function getNameForPath(path: NodePath<>): string {
|
|
138
173
|
const {node, parent, parentPath} = path;
|
|
139
|
-
if (
|
|
174
|
+
if (isProgram(node)) {
|
|
140
175
|
return '<global>';
|
|
141
176
|
}
|
|
142
|
-
|
|
177
|
+
|
|
178
|
+
let {id} = (path: any);
|
|
143
179
|
// has an `id` so we don't need to infer one
|
|
144
180
|
if (node.id) {
|
|
181
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
145
182
|
return node.id.name;
|
|
146
183
|
}
|
|
147
184
|
let propertyPath;
|
|
148
185
|
let kind = '';
|
|
149
|
-
if (
|
|
186
|
+
if (isObjectMethod(node) || isClassMethod(node)) {
|
|
150
187
|
id = node.key;
|
|
151
188
|
if (node.kind !== 'method' && node.kind !== 'constructor') {
|
|
152
189
|
kind = node.kind;
|
|
153
190
|
}
|
|
154
191
|
propertyPath = path;
|
|
155
|
-
} else if (
|
|
192
|
+
} else if (isObjectProperty(parent) || isClassProperty(parent)) {
|
|
156
193
|
// { foo() {} };
|
|
157
194
|
id = parent.key;
|
|
158
195
|
propertyPath = parentPath;
|
|
159
|
-
} else if (
|
|
196
|
+
} else if (isVariableDeclarator(parent)) {
|
|
160
197
|
// let foo = function () {};
|
|
161
198
|
id = parent.id;
|
|
162
|
-
} else if (
|
|
199
|
+
} else if (isAssignmentExpression(parent)) {
|
|
163
200
|
// foo = function () {};
|
|
164
201
|
id = parent.left;
|
|
165
|
-
} else if (
|
|
166
|
-
|
|
202
|
+
} else if (isJSXExpressionContainer(parent)) {
|
|
203
|
+
const grandParentNode = parentPath?.parentPath?.node;
|
|
204
|
+
if (isJSXElement(grandParentNode)) {
|
|
167
205
|
// <foo>{function () {}}</foo>
|
|
168
|
-
const openingElement =
|
|
169
|
-
id = t.
|
|
170
|
-
|
|
171
|
-
t.
|
|
206
|
+
const openingElement = grandParentNode.openingElement;
|
|
207
|
+
id = t.jsxMemberExpression(
|
|
208
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
209
|
+
t.jsxMemberExpression(openingElement.name, t.jsxIdentifier('props')),
|
|
210
|
+
t.jsxIdentifier('children'),
|
|
172
211
|
);
|
|
173
|
-
} else if (
|
|
212
|
+
} else if (isJSXAttribute(grandParentNode)) {
|
|
174
213
|
// <foo bar={function () {}} />
|
|
175
|
-
const openingElement = parentPath
|
|
176
|
-
const prop =
|
|
177
|
-
id = t.
|
|
178
|
-
|
|
214
|
+
const openingElement = parentPath?.parentPath?.parentPath?.node;
|
|
215
|
+
const prop = grandParentNode;
|
|
216
|
+
id = t.jsxMemberExpression(
|
|
217
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
218
|
+
t.jsxMemberExpression(openingElement.name, t.jsxIdentifier('props')),
|
|
219
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
179
220
|
prop.name,
|
|
180
221
|
);
|
|
181
222
|
}
|
|
@@ -184,20 +225,23 @@ function getNameForPath(path: Path): string {
|
|
|
184
225
|
let name = getNameFromId(id);
|
|
185
226
|
|
|
186
227
|
if (name == null) {
|
|
187
|
-
if (
|
|
228
|
+
if (isCallExpression(parent) || isNewExpression(parent)) {
|
|
188
229
|
// foo(function () {})
|
|
189
230
|
const argIndex = parent.arguments.indexOf(node);
|
|
190
231
|
if (argIndex !== -1) {
|
|
191
232
|
const calleeName = getNameFromId(parent.callee);
|
|
192
233
|
// var f = Object.freeze(function () {})
|
|
193
234
|
if (CALLEES_TO_SKIP.indexOf(calleeName) !== -1) {
|
|
194
|
-
return getNameForPath(parentPath);
|
|
235
|
+
return getNameForPath(nullthrows(parentPath));
|
|
195
236
|
}
|
|
196
237
|
if (calleeName) {
|
|
197
238
|
return `${calleeName}$argument_${argIndex}`;
|
|
198
239
|
}
|
|
199
240
|
}
|
|
200
241
|
}
|
|
242
|
+
if (isTypeCastExpression(parent) && parent.expression === node) {
|
|
243
|
+
return getNameForPath(nullthrows(parentPath));
|
|
244
|
+
}
|
|
201
245
|
return ANONYMOUS_NAME;
|
|
202
246
|
}
|
|
203
247
|
|
|
@@ -206,14 +250,16 @@ function getNameForPath(path: Path): string {
|
|
|
206
250
|
}
|
|
207
251
|
|
|
208
252
|
if (propertyPath) {
|
|
209
|
-
if (
|
|
253
|
+
if (isClassBody(propertyPath.parent)) {
|
|
254
|
+
// $FlowFixMe Disvoered when typing babel-traverse
|
|
210
255
|
const className = getNameForPath(propertyPath.parentPath.parentPath);
|
|
211
256
|
if (className !== ANONYMOUS_NAME) {
|
|
257
|
+
// $FlowFixMe Flow error uncovered by typing Babel more strictly
|
|
212
258
|
const separator = propertyPath.node.static ? '.' : '#';
|
|
213
259
|
name = className + separator + name;
|
|
214
260
|
}
|
|
215
|
-
} else if (
|
|
216
|
-
const objectName = getNameForPath(propertyPath.parentPath);
|
|
261
|
+
} else if (isObjectExpression(propertyPath.parent)) {
|
|
262
|
+
const objectName = getNameForPath(nullthrows(propertyPath.parentPath));
|
|
217
263
|
if (objectName !== ANONYMOUS_NAME) {
|
|
218
264
|
name = objectName + '.' + name;
|
|
219
265
|
}
|
|
@@ -223,15 +269,17 @@ function getNameForPath(path: Path): string {
|
|
|
223
269
|
return name;
|
|
224
270
|
}
|
|
225
271
|
|
|
226
|
-
function isAnyMemberExpression(node:
|
|
227
|
-
return
|
|
272
|
+
function isAnyMemberExpression(node: Node): boolean %checks {
|
|
273
|
+
return (
|
|
274
|
+
node.type === 'MemberExpression' || node.type === 'JSXMemberExpression'
|
|
275
|
+
);
|
|
228
276
|
}
|
|
229
277
|
|
|
230
|
-
function isAnyIdentifier(node:
|
|
231
|
-
return
|
|
278
|
+
function isAnyIdentifier(node: Node): boolean %checks {
|
|
279
|
+
return isIdentifier(node) || isJSXIdentifier(node);
|
|
232
280
|
}
|
|
233
281
|
|
|
234
|
-
function getNameFromId(id:
|
|
282
|
+
function getNameFromId(id: Node): ?string {
|
|
235
283
|
const parts = getNamePartsFromId(id);
|
|
236
284
|
|
|
237
285
|
if (!parts.length) {
|
|
@@ -251,16 +299,16 @@ function getNameFromId(id: Ast): ?string {
|
|
|
251
299
|
return parts.join('.');
|
|
252
300
|
}
|
|
253
301
|
|
|
254
|
-
function getNamePartsFromId(id:
|
|
302
|
+
function getNamePartsFromId(id: Node): $ReadOnlyArray<string> {
|
|
255
303
|
if (!id) {
|
|
256
304
|
return [];
|
|
257
305
|
}
|
|
258
306
|
|
|
259
|
-
if (
|
|
307
|
+
if (isCallExpression(id) || isNewExpression(id)) {
|
|
260
308
|
return getNamePartsFromId(id.callee);
|
|
261
309
|
}
|
|
262
310
|
|
|
263
|
-
if (
|
|
311
|
+
if (isTypeCastExpression(id)) {
|
|
264
312
|
return getNamePartsFromId(id.expression);
|
|
265
313
|
}
|
|
266
314
|
|
|
@@ -268,21 +316,21 @@ function getNamePartsFromId(id: Ast): $ReadOnlyArray<string> {
|
|
|
268
316
|
|
|
269
317
|
if (isAnyIdentifier(id)) {
|
|
270
318
|
name = id.name;
|
|
271
|
-
} else if (
|
|
319
|
+
} else if (isNullLiteral(id)) {
|
|
272
320
|
name = 'null';
|
|
273
|
-
} else if (
|
|
274
|
-
name = `_${id.pattern}_${id.flags}`;
|
|
275
|
-
} else if (
|
|
321
|
+
} else if (isRegExpLiteral(id)) {
|
|
322
|
+
name = `_${id.pattern}_${id.flags ?? ''}`;
|
|
323
|
+
} else if (isTemplateLiteral(id)) {
|
|
276
324
|
name = id.quasis.map(quasi => quasi.value.raw).join('');
|
|
277
|
-
} else if (
|
|
278
|
-
name = id.value
|
|
325
|
+
} else if (isLiteral(id) && id.value != null) {
|
|
326
|
+
name = String(id.value);
|
|
279
327
|
}
|
|
280
328
|
|
|
281
329
|
if (name != null) {
|
|
282
330
|
return [t.toBindingIdentifierName(name)];
|
|
283
331
|
}
|
|
284
332
|
|
|
285
|
-
if (
|
|
333
|
+
if (isImport(id)) {
|
|
286
334
|
name = 'import';
|
|
287
335
|
}
|
|
288
336
|
|
|
@@ -294,7 +342,7 @@ function getNamePartsFromId(id: Ast): $ReadOnlyArray<string> {
|
|
|
294
342
|
if (
|
|
295
343
|
isAnyIdentifier(id.object) &&
|
|
296
344
|
id.object.name === 'Symbol' &&
|
|
297
|
-
(isAnyIdentifier(id.property) ||
|
|
345
|
+
(isAnyIdentifier(id.property) || isLiteral(id.property))
|
|
298
346
|
) {
|
|
299
347
|
const propertyName = getNameFromId(id.property);
|
|
300
348
|
if (propertyName) {
|