@babel/traverse 7.20.0 → 7.20.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.

Potentially problematic release.


This version of @babel/traverse might be problematic. Click here for more details.

Files changed (57) hide show
  1. package/lib/cache.js +0 -3
  2. package/lib/cache.js.map +1 -1
  3. package/lib/context.js +7 -21
  4. package/lib/context.js.map +1 -1
  5. package/lib/hub.js +0 -6
  6. package/lib/hub.js.map +1 -1
  7. package/lib/index.js +3 -21
  8. package/lib/index.js.map +1 -1
  9. package/lib/path/ancestry.js +3 -23
  10. package/lib/path/ancestry.js.map +1 -1
  11. package/lib/path/comments.js +0 -4
  12. package/lib/path/comments.js.map +1 -1
  13. package/lib/path/context.js +14 -54
  14. package/lib/path/context.js.map +1 -1
  15. package/lib/path/conversion.js +23 -78
  16. package/lib/path/conversion.js.map +1 -1
  17. package/lib/path/evaluation.js +9 -85
  18. package/lib/path/evaluation.js.map +1 -1
  19. package/lib/path/family.js +6 -73
  20. package/lib/path/family.js.map +1 -1
  21. package/lib/path/index.js +2 -61
  22. package/lib/path/index.js.map +1 -1
  23. package/lib/path/inference/index.js +2 -27
  24. package/lib/path/inference/index.js.map +1 -1
  25. package/lib/path/inference/inferer-reference.js +10 -31
  26. package/lib/path/inference/inferer-reference.js.map +1 -1
  27. package/lib/path/inference/inferers.js +4 -44
  28. package/lib/path/inference/inferers.js.map +1 -1
  29. package/lib/path/inference/util.js +0 -4
  30. package/lib/path/inference/util.js.map +1 -1
  31. package/lib/path/introspection.js +17 -59
  32. package/lib/path/introspection.js.map +1 -1
  33. package/lib/path/lib/hoister.js +7 -23
  34. package/lib/path/lib/hoister.js.map +1 -1
  35. package/lib/path/lib/removal-hooks.js +7 -3
  36. package/lib/path/lib/removal-hooks.js.map +1 -1
  37. package/lib/path/lib/virtual-types-validator.js +0 -23
  38. package/lib/path/lib/virtual-types-validator.js.map +1 -1
  39. package/lib/path/lib/virtual-types.js +1 -0
  40. package/lib/path/lib/virtual-types.js.map +1 -1
  41. package/lib/path/modification.js +12 -47
  42. package/lib/path/modification.js.map +1 -1
  43. package/lib/path/removal.js +0 -16
  44. package/lib/path/removal.js.map +1 -1
  45. package/lib/path/replacement.js +8 -50
  46. package/lib/path/replacement.js.map +1 -1
  47. package/lib/scope/binding.js +2 -14
  48. package/lib/scope/binding.js.map +1 -1
  49. package/lib/scope/index.js +19 -184
  50. package/lib/scope/index.js.map +1 -1
  51. package/lib/scope/lib/renamer.js +2 -25
  52. package/lib/scope/lib/renamer.js.map +1 -1
  53. package/lib/traverse-node.js +0 -7
  54. package/lib/traverse-node.js.map +1 -1
  55. package/lib/visitors.js +13 -44
  56. package/lib/visitors.js.map +1 -1
  57. package/package.json +4 -4
@@ -22,9 +22,7 @@ exports.matchesPattern = matchesPattern;
22
22
  exports.referencesImport = referencesImport;
23
23
  exports.resolve = resolve;
24
24
  exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
25
-
26
25
  var _t = require("@babel/types");
27
-
28
26
  const {
29
27
  STATEMENT_OR_BLOCK_KEYS,
30
28
  VISITOR_KEYS,
@@ -43,7 +41,6 @@ function matchesPattern(pattern, allowPartial) {
43
41
 
44
42
  function has(key) {
45
43
  const val = this.node && this.node[key];
46
-
47
44
  if (val && Array.isArray(val)) {
48
45
  return !!val.length;
49
46
  } else {
@@ -56,6 +53,7 @@ function isStatic() {
56
53
  }
57
54
 
58
55
  const is = has;
56
+
59
57
  exports.is = is;
60
58
 
61
59
  function isnt(key) {
@@ -78,20 +76,17 @@ function canSwapBetweenExpressionAndStatement(replacement) {
78
76
  if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
79
77
  return false;
80
78
  }
81
-
82
79
  if (this.isExpression()) {
83
80
  return isBlockStatement(replacement);
84
81
  } else if (this.isBlockStatement()) {
85
82
  return isExpression(replacement);
86
83
  }
87
-
88
84
  return false;
89
85
  }
90
86
 
91
87
  function isCompletionRecord(allowInsideFunction) {
92
88
  let path = this;
93
89
  let first = true;
94
-
95
90
  do {
96
91
  const {
97
92
  type,
@@ -101,14 +96,12 @@ function isCompletionRecord(allowInsideFunction) {
101
96
  if (!first && (path.isFunction() || type === "StaticBlock")) {
102
97
  return !!allowInsideFunction;
103
98
  }
104
-
105
99
  first = false;
106
100
 
107
101
  if (Array.isArray(container) && path.key !== container.length - 1) {
108
102
  return false;
109
103
  }
110
104
  } while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
111
-
112
105
  return true;
113
106
  }
114
107
 
@@ -128,10 +121,8 @@ function referencesImport(moduleSource, importName) {
128
121
  const object = this.get("object");
129
122
  return object.isReferencedIdentifier() && object.referencesImport(moduleSource, "*");
130
123
  }
131
-
132
124
  return false;
133
125
  }
134
-
135
126
  const binding = this.scope.getBinding(this.node.name);
136
127
  if (!binding || binding.kind !== "module") return false;
137
128
  const path = binding.path;
@@ -143,43 +134,34 @@ function referencesImport(moduleSource, importName) {
143
134
  } else {
144
135
  return false;
145
136
  }
146
-
147
137
  if (path.isImportDefaultSpecifier() && importName === "default") {
148
138
  return true;
149
139
  }
150
-
151
140
  if (path.isImportNamespaceSpecifier() && importName === "*") {
152
141
  return true;
153
142
  }
154
-
155
143
  if (path.isImportSpecifier() && isIdentifier(path.node.imported, {
156
144
  name: importName
157
145
  })) {
158
146
  return true;
159
147
  }
160
-
161
148
  return false;
162
149
  }
163
150
 
164
151
  function getSource() {
165
152
  const node = this.node;
166
-
167
153
  if (node.end) {
168
154
  const code = this.hub.getCode();
169
155
  if (code) return code.slice(node.start, node.end);
170
156
  }
171
-
172
157
  return "";
173
158
  }
174
-
175
159
  function willIMaybeExecuteBefore(target) {
176
160
  return this._guessExecutionStatusRelativeTo(target) !== "after";
177
161
  }
178
-
179
162
  function getOuterFunction(path) {
180
163
  return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path;
181
164
  }
182
-
183
165
  function isExecutionUncertain(type, key) {
184
166
  switch (type) {
185
167
  case "LogicalExpression":
@@ -212,28 +194,23 @@ function isExecutionUncertain(type, key) {
212
194
 
213
195
  case "OptionalCallExpression":
214
196
  return key === "arguments";
215
-
216
197
  default:
217
198
  return false;
218
199
  }
219
200
  }
220
-
221
201
  function isExecutionUncertainInList(paths, maxIndex) {
222
202
  for (let i = 0; i < maxIndex; i++) {
223
203
  const path = paths[i];
224
-
225
204
  if (isExecutionUncertain(path.parent.type, path.parentKey)) {
226
205
  return true;
227
206
  }
228
207
  }
229
-
230
208
  return false;
231
209
  }
232
210
 
233
211
  function _guessExecutionStatusRelativeTo(target) {
234
212
  return _guessExecutionStatusRelativeToCached(this, target, new Map());
235
213
  }
236
-
237
214
  function _guessExecutionStatusRelativeToCached(base, target, cache) {
238
215
  const funcParent = {
239
216
  this: getOuterFunction(base),
@@ -243,38 +220,34 @@ function _guessExecutionStatusRelativeToCached(base, target, cache) {
243
220
  if (funcParent.target.node !== funcParent.this.node) {
244
221
  return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);
245
222
  }
246
-
247
223
  const paths = {
248
224
  target: target.getAncestry(),
249
225
  this: base.getAncestry()
250
226
  };
227
+
251
228
  if (paths.target.indexOf(base) >= 0) return "after";
252
229
  if (paths.this.indexOf(target) >= 0) return "before";
230
+
253
231
  let commonPath;
254
232
  const commonIndex = {
255
233
  target: 0,
256
234
  this: 0
257
235
  };
258
-
259
236
  while (!commonPath && commonIndex.this < paths.this.length) {
260
237
  const path = paths.this[commonIndex.this];
261
238
  commonIndex.target = paths.target.indexOf(path);
262
-
263
239
  if (commonIndex.target >= 0) {
264
240
  commonPath = path;
265
241
  } else {
266
242
  commonIndex.this++;
267
243
  }
268
244
  }
269
-
270
245
  if (!commonPath) {
271
246
  throw new Error("Internal Babel error - The two compared nodes" + " don't appear to belong to the same program.");
272
247
  }
273
-
274
248
  if (isExecutionUncertainInList(paths.this, commonIndex.this - 1) || isExecutionUncertainInList(paths.target, commonIndex.target - 1)) {
275
249
  return "unknown";
276
250
  }
277
-
278
251
  const divergence = {
279
252
  this: paths.this[commonIndex.this - 1],
280
253
  target: paths.target[commonIndex.target - 1]
@@ -293,13 +266,13 @@ function _guessExecutionStatusRelativeToCached(base, target, cache) {
293
266
  }
294
267
 
295
268
  const executionOrderCheckedNodes = new Set();
296
-
297
269
  function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) {
298
270
  if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
299
271
  return "unknown";
300
272
  }
301
273
 
302
274
  const binding = target.scope.getBinding(target.node.id.name);
275
+
303
276
  if (!binding.references) return "before";
304
277
  const referencePaths = binding.referencePaths;
305
278
  let allStatus;
@@ -307,17 +280,14 @@ function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target,
307
280
  for (const path of referencePaths) {
308
281
  const childOfFunction = !!path.find(path => path.node === target.node);
309
282
  if (childOfFunction) continue;
310
-
311
283
  if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
312
284
  return "unknown";
313
285
  }
314
286
 
315
287
  if (executionOrderCheckedNodes.has(path.node)) continue;
316
288
  executionOrderCheckedNodes.add(path.node);
317
-
318
289
  try {
319
290
  const status = _guessExecutionStatusRelativeToCached(base, path, cache);
320
-
321
291
  if (allStatus && allStatus !== status) {
322
292
  return "unknown";
323
293
  } else {
@@ -327,21 +297,16 @@ function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target,
327
297
  executionOrderCheckedNodes.delete(path.node);
328
298
  }
329
299
  }
330
-
331
300
  return allStatus;
332
301
  }
333
-
334
302
  function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, cache) {
335
303
  let nodeMap = cache.get(base.node);
336
-
337
304
  if (!nodeMap) {
338
305
  cache.set(base.node, nodeMap = new Map());
339
306
  } else if (nodeMap.has(target.node)) {
340
307
  return nodeMap.get(target.node);
341
308
  }
342
-
343
309
  const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache);
344
-
345
310
  nodeMap.set(target.node, result);
346
311
  return result;
347
312
  }
@@ -349,22 +314,23 @@ function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, c
349
314
  function resolve(dangerous, resolved) {
350
315
  return this._resolve(dangerous, resolved) || this;
351
316
  }
352
-
353
317
  function _resolve(dangerous, resolved) {
354
318
  if (resolved && resolved.indexOf(this) >= 0) return;
319
+
355
320
  resolved = resolved || [];
356
321
  resolved.push(this);
357
-
358
322
  if (this.isVariableDeclarator()) {
359
323
  if (this.get("id").isIdentifier()) {
360
324
  return this.get("init").resolve(dangerous, resolved);
361
- } else {}
325
+ } else {
326
+ }
362
327
  } else if (this.isReferencedIdentifier()) {
363
328
  const binding = this.scope.getBinding(this.node.name);
364
329
  if (!binding) return;
330
+
365
331
  if (!binding.constant) return;
366
- if (binding.kind === "module") return;
367
332
 
333
+ if (binding.kind === "module") return;
368
334
  if (binding.path !== this) {
369
335
  const ret = binding.path.resolve(dangerous, resolved);
370
336
  if (this.find(parent => parent.node === ret.node)) return;
@@ -373,20 +339,22 @@ function _resolve(dangerous, resolved) {
373
339
  } else if (this.isTypeCastExpression()) {
374
340
  return this.get("expression").resolve(dangerous, resolved);
375
341
  } else if (dangerous && this.isMemberExpression()) {
342
+
376
343
  const targetKey = this.toComputedKey();
377
344
  if (!isLiteral(targetKey)) return;
345
+
378
346
  const targetName = targetKey.value;
379
347
  const target = this.get("object").resolve(dangerous, resolved);
380
-
381
348
  if (target.isObjectExpression()) {
382
349
  const props = target.get("properties");
383
-
384
350
  for (const prop of props) {
385
351
  if (!prop.isProperty()) continue;
386
352
  const key = prop.get("key");
353
+
387
354
  let match = prop.isnt("computed") && key.isIdentifier({
388
355
  name: targetName
389
356
  });
357
+
390
358
  match = match || key.isLiteral({
391
359
  value: targetName
392
360
  });
@@ -399,41 +367,35 @@ function _resolve(dangerous, resolved) {
399
367
  }
400
368
  }
401
369
  }
402
-
403
370
  function isConstantExpression() {
404
371
  if (this.isIdentifier()) {
405
372
  const binding = this.scope.getBinding(this.node.name);
406
373
  if (!binding) return false;
407
374
  return binding.constant;
408
375
  }
409
-
410
376
  if (this.isLiteral()) {
411
377
  if (this.isRegExpLiteral()) {
412
378
  return false;
413
379
  }
414
-
415
380
  if (this.isTemplateLiteral()) {
416
381
  return this.get("expressions").every(expression => expression.isConstantExpression());
417
382
  }
418
-
419
383
  return true;
420
384
  }
421
-
422
385
  if (this.isUnaryExpression()) {
423
386
  if (this.node.operator !== "void") {
424
387
  return false;
425
388
  }
426
-
427
389
  return this.get("argument").isConstantExpression();
428
390
  }
429
-
430
391
  if (this.isBinaryExpression()) {
431
- return this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
392
+ const {
393
+ operator
394
+ } = this.node;
395
+ return operator !== "in" && operator !== "instanceof" && this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
432
396
  }
433
-
434
397
  return false;
435
398
  }
436
-
437
399
  function isInStrictMode() {
438
400
  const start = this.isProgram() ? this : this.parentPath;
439
401
  const strictParent = start.find(path => {
@@ -441,13 +403,10 @@ function isInStrictMode() {
441
403
  sourceType: "module"
442
404
  })) return true;
443
405
  if (path.isClass()) return true;
444
-
445
406
  if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
446
407
  return false;
447
408
  }
448
-
449
409
  let body;
450
-
451
410
  if (path.isFunction()) {
452
411
  body = path.node.body;
453
412
  } else if (path.isProgram()) {
@@ -455,7 +414,6 @@ function isInStrictMode() {
455
414
  } else {
456
415
  return false;
457
416
  }
458
-
459
417
  for (const directive of body.directives) {
460
418
  if (directive.value.value === "use strict") {
461
419
  return true;
@@ -1 +1 @@
1
- {"version":3,"names":["STATEMENT_OR_BLOCK_KEYS","VISITOR_KEYS","isBlockStatement","isExpression","isIdentifier","isLiteral","isStringLiteral","isType","matchesPattern","_matchesPattern","pattern","allowPartial","node","has","key","val","Array","isArray","length","isStatic","scope","is","isnt","equals","value","isNodeType","type","canHaveVariableDeclarationOrExpression","parentPath","isFor","canSwapBetweenExpressionAndStatement","replacement","isArrowFunctionExpression","isCompletionRecord","allowInsideFunction","path","first","container","isFunction","isProgram","isDoExpression","isStatementOrBlock","isLabeledStatement","includes","referencesImport","moduleSource","importName","isReferencedIdentifier","isJSXMemberExpression","property","name","isMemberExpression","isOptionalMemberExpression","computed","object","get","binding","getBinding","kind","parent","isImportDeclaration","source","isImportDefaultSpecifier","isImportNamespaceSpecifier","isImportSpecifier","imported","getSource","end","code","hub","getCode","slice","start","willIMaybeExecuteBefore","target","_guessExecutionStatusRelativeTo","getOuterFunction","getFunctionParent","getProgramParent","isExecutionUncertain","isExecutionUncertainInList","paths","maxIndex","i","parentKey","_guessExecutionStatusRelativeToCached","Map","base","cache","funcParent","this","_guessExecutionStatusRelativeToDifferentFunctionsCached","getAncestry","indexOf","commonPath","commonIndex","Error","divergence","listKey","keys","keyPosition","executionOrderCheckedNodes","Set","_guessExecutionStatusRelativeToDifferentFunctionsInternal","isFunctionDeclaration","isExportDeclaration","id","references","referencePaths","allStatus","childOfFunction","find","isCallExpression","add","status","delete","nodeMap","set","result","resolve","dangerous","resolved","_resolve","push","isVariableDeclarator","constant","ret","isTypeCastExpression","targetKey","toComputedKey","targetName","isObjectExpression","props","prop","isProperty","match","isArrayExpression","isNaN","elems","elem","isConstantExpression","isRegExpLiteral","isTemplateLiteral","every","expression","isUnaryExpression","operator","isBinaryExpression","isInStrictMode","strictParent","sourceType","isClass","body","directive","directives"],"sources":["../../src/path/introspection.ts"],"sourcesContent":["// This file contains methods responsible for introspecting the current path for certain values.\n\nimport type NodePath from \"./index\";\nimport {\n STATEMENT_OR_BLOCK_KEYS,\n VISITOR_KEYS,\n isBlockStatement,\n isExpression,\n isIdentifier,\n isLiteral,\n isStringLiteral,\n isType,\n matchesPattern as _matchesPattern,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\n/**\n * Match the current node if it matches the provided `pattern`.\n *\n * For example, given the match `React.createClass` it would match the\n * parsed nodes of `React.createClass` and `React[\"createClass\"]`.\n */\n\nexport function matchesPattern(\n this: NodePath,\n pattern: string,\n allowPartial?: boolean,\n): boolean {\n return _matchesPattern(this.node, pattern, allowPartial);\n}\n\n/**\n * Check whether we have the input `key`. If the `key` references an array then we check\n * if the array has any items, otherwise we just check if it's falsy.\n */\n\nexport function has<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n): boolean {\n const val = this.node && this.node[key];\n if (val && Array.isArray(val)) {\n return !!val.length;\n } else {\n return !!val;\n }\n}\n\n/**\n * Description\n */\n\nexport function isStatic(this: NodePath): boolean {\n return this.scope.isStatic(this.node);\n}\n\n/**\n * Alias of `has`.\n */\n\nexport const is = has;\n\n/**\n * Opposite of `has`.\n */\n\nexport function isnt<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n): boolean {\n return !this.has(key);\n}\n\n/**\n * Check whether the path node `key` strict equals `value`.\n */\n\nexport function equals<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n value: any,\n): boolean {\n return this.node[key] === value;\n}\n\n/**\n * Check the type against our stored internal type of the node. This is handy when a node has\n * been removed yet we still internally know the type and need it to calculate node replacement.\n */\n\nexport function isNodeType(this: NodePath, type: string): boolean {\n return isType(this.type, type);\n}\n\n/**\n * This checks whether or not we're in one of the following positions:\n *\n * for (KEY in right);\n * for (KEY;;);\n *\n * This is because these spots allow VariableDeclarations AND normal expressions so we need\n * to tell the path replacement that it's ok to replace this with an expression.\n */\n\nexport function canHaveVariableDeclarationOrExpression(this: NodePath) {\n return (\n (this.key === \"init\" || this.key === \"left\") && this.parentPath.isFor()\n );\n}\n\n/**\n * This checks whether we are swapping an arrow function's body between an\n * expression and a block statement (or vice versa).\n *\n * This is because arrow functions may implicitly return an expression, which\n * is the same as containing a block statement.\n */\n\nexport function canSwapBetweenExpressionAndStatement(\n this: NodePath,\n replacement: t.Node,\n): boolean {\n if (this.key !== \"body\" || !this.parentPath.isArrowFunctionExpression()) {\n return false;\n }\n\n if (this.isExpression()) {\n return isBlockStatement(replacement);\n } else if (this.isBlockStatement()) {\n return isExpression(replacement);\n }\n\n return false;\n}\n\n/**\n * Check whether the current path references a completion record\n */\n\nexport function isCompletionRecord(\n this: NodePath,\n allowInsideFunction?: boolean,\n): boolean {\n let path = this;\n let first = true;\n\n do {\n const { type, container } = path;\n\n // we're in a function so can't be a completion record\n if (!first && (path.isFunction() || type === \"StaticBlock\")) {\n return !!allowInsideFunction;\n }\n\n first = false;\n\n // check to see if we're the last item in the container and if we are\n // we're a completion record!\n if (Array.isArray(container) && path.key !== container.length - 1) {\n return false;\n }\n } while (\n (path = path.parentPath) &&\n !path.isProgram() &&\n !path.isDoExpression()\n );\n\n return true;\n}\n\n/**\n * Check whether or not the current `key` allows either a single statement or block statement\n * so we can explode it if necessary.\n */\n\nexport function isStatementOrBlock(this: NodePath): boolean {\n if (\n this.parentPath.isLabeledStatement() ||\n isBlockStatement(this.container)\n ) {\n return false;\n } else {\n return STATEMENT_OR_BLOCK_KEYS.includes(this.key as string);\n }\n}\n\n/**\n * Check if the currently assigned path references the `importName` of `moduleSource`.\n */\n\nexport function referencesImport(\n this: NodePath,\n moduleSource: string,\n importName: string,\n): boolean {\n if (!this.isReferencedIdentifier()) {\n if (\n (this.isJSXMemberExpression() &&\n this.node.property.name === importName) ||\n ((this.isMemberExpression() || this.isOptionalMemberExpression()) &&\n (this.node.computed\n ? isStringLiteral(this.node.property, { value: importName })\n : (this.node.property as t.Identifier).name === importName))\n ) {\n const object = (\n this as NodePath<t.MemberExpression | t.OptionalMemberExpression>\n ).get(\"object\");\n return (\n object.isReferencedIdentifier() &&\n object.referencesImport(moduleSource, \"*\")\n );\n }\n\n return false;\n }\n\n const binding = this.scope.getBinding((this.node as t.Identifier).name);\n if (!binding || binding.kind !== \"module\") return false;\n\n const path = binding.path;\n const parent = path.parentPath;\n if (!parent.isImportDeclaration()) return false;\n\n // check moduleSource\n if (parent.node.source.value === moduleSource) {\n if (!importName) return true;\n } else {\n return false;\n }\n\n if (path.isImportDefaultSpecifier() && importName === \"default\") {\n return true;\n }\n\n if (path.isImportNamespaceSpecifier() && importName === \"*\") {\n return true;\n }\n\n if (\n path.isImportSpecifier() &&\n isIdentifier(path.node.imported, { name: importName })\n ) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Get the source code associated with this node.\n */\n\nexport function getSource(this: NodePath): string {\n const node = this.node;\n if (node.end) {\n const code = this.hub.getCode();\n if (code) return code.slice(node.start, node.end);\n }\n return \"\";\n}\n\nexport function willIMaybeExecuteBefore(\n this: NodePath,\n target: NodePath,\n): boolean {\n return this._guessExecutionStatusRelativeTo(target) !== \"after\";\n}\n\nfunction getOuterFunction(path: NodePath) {\n return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path;\n}\n\nfunction isExecutionUncertain(type: t.Node[\"type\"], key: string) {\n switch (type) {\n // a && FOO\n // a || FOO\n case \"LogicalExpression\":\n return key === \"right\";\n\n // a ? FOO : FOO\n // if (a) FOO; else FOO;\n case \"ConditionalExpression\":\n case \"IfStatement\":\n return key === \"consequent\" || key === \"alternate\";\n\n // while (a) FOO;\n case \"WhileStatement\":\n case \"DoWhileStatement\":\n case \"ForInStatement\":\n case \"ForOfStatement\":\n return key === \"body\";\n\n // for (a; b; FOO) FOO;\n case \"ForStatement\":\n return key === \"body\" || key === \"update\";\n\n // switch (a) { FOO }\n case \"SwitchStatement\":\n return key === \"cases\";\n\n // try { a } catch FOO finally { b }\n case \"TryStatement\":\n return key === \"handler\";\n\n // var [ x = FOO ]\n case \"AssignmentPattern\":\n return key === \"right\";\n\n // a?.[FOO]\n case \"OptionalMemberExpression\":\n return key === \"property\";\n\n // a?.(FOO)\n case \"OptionalCallExpression\":\n return key === \"arguments\";\n\n default:\n return false;\n }\n}\n\nfunction isExecutionUncertainInList(paths: NodePath[], maxIndex: number) {\n for (let i = 0; i < maxIndex; i++) {\n const path = paths[i];\n if (isExecutionUncertain(path.parent.type, path.parentKey)) {\n return true;\n }\n }\n return false;\n}\n\n// TODO (Babel 8)\n// This can be { before: boolean, after: boolean, unknown: boolean }.\n// This allows transforms like the tdz one to treat cases when the status\n// is both before and unknown/after like if it were before.\ntype RelativeExecutionStatus = \"before\" | \"after\" | \"unknown\";\n\ntype ExecutionStatusCache = Map<t.Node, Map<t.Node, RelativeExecutionStatus>>;\n\n/**\n * Given a `target` check the execution status of it relative to the current path.\n *\n * \"Execution status\" simply refers to where or not we **think** this will execute\n * before or after the input `target` element.\n */\n\nexport function _guessExecutionStatusRelativeTo(\n this: NodePath,\n target: NodePath,\n): RelativeExecutionStatus {\n return _guessExecutionStatusRelativeToCached(this, target, new Map());\n}\n\nfunction _guessExecutionStatusRelativeToCached(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n // check if the two paths are in different functions, we can't track execution of these\n const funcParent = {\n this: getOuterFunction(base),\n target: getOuterFunction(target),\n };\n\n // here we check the `node` equality as sometimes we may have different paths for the\n // same node due to path thrashing\n if (funcParent.target.node !== funcParent.this.node) {\n return _guessExecutionStatusRelativeToDifferentFunctionsCached(\n base,\n funcParent.target,\n cache,\n );\n }\n\n const paths = {\n target: target.getAncestry(),\n this: base.getAncestry(),\n };\n\n // If this is an ancestor of the target path,\n // e.g. f(g); where this is f and target is g.\n if (paths.target.indexOf(base) >= 0) return \"after\";\n if (paths.this.indexOf(target) >= 0) return \"before\";\n\n // get ancestor where the branches intersect\n let commonPath;\n const commonIndex = { target: 0, this: 0 };\n\n while (!commonPath && commonIndex.this < paths.this.length) {\n const path = paths.this[commonIndex.this];\n commonIndex.target = paths.target.indexOf(path);\n if (commonIndex.target >= 0) {\n commonPath = path;\n } else {\n commonIndex.this++;\n }\n }\n\n if (!commonPath) {\n throw new Error(\n \"Internal Babel error - The two compared nodes\" +\n \" don't appear to belong to the same program.\",\n );\n }\n\n if (\n isExecutionUncertainInList(paths.this, commonIndex.this - 1) ||\n isExecutionUncertainInList(paths.target, commonIndex.target - 1)\n ) {\n return \"unknown\";\n }\n\n const divergence = {\n this: paths.this[commonIndex.this - 1],\n target: paths.target[commonIndex.target - 1],\n };\n\n // container list so let's see which one is after the other\n // e.g. [ THIS, TARGET ]\n if (\n divergence.target.listKey &&\n divergence.this.listKey &&\n divergence.target.container === divergence.this.container\n ) {\n return divergence.target.key > divergence.this.key ? \"before\" : \"after\";\n }\n\n // otherwise we're associated by a parent node, check which key comes before the other\n const keys = VISITOR_KEYS[commonPath.type];\n const keyPosition = {\n this: keys.indexOf(divergence.this.parentKey as string),\n target: keys.indexOf(divergence.target.parentKey as string),\n };\n return keyPosition.target > keyPosition.this ? \"before\" : \"after\";\n}\n\n// Used to avoid infinite recursion in cases like\n// function f() { if (false) f(); }\n// f();\n// It also works with indirect recursion.\nconst executionOrderCheckedNodes = new Set();\n\nfunction _guessExecutionStatusRelativeToDifferentFunctionsInternal(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n if (\n !target.isFunctionDeclaration() ||\n target.parentPath.isExportDeclaration()\n ) {\n return \"unknown\";\n }\n\n // so we're in a completely different function, if this is a function declaration\n // then we can be a bit smarter and handle cases where the function is either\n // a. not called at all (part of an export)\n // b. called directly\n const binding = target.scope.getBinding(target.node.id.name);\n\n // no references!\n if (!binding.references) return \"before\";\n\n const referencePaths: Array<NodePath> = binding.referencePaths;\n\n let allStatus;\n\n // verify that all the calls have the same execution status\n for (const path of referencePaths) {\n // if a reference is a child of the function we're checking against then we can\n // safely ignore it\n const childOfFunction = !!path.find(path => path.node === target.node);\n if (childOfFunction) continue;\n\n if (path.key !== \"callee\" || !path.parentPath.isCallExpression()) {\n // This function is passed as a reference, so we don't\n // know when it will be called.\n return \"unknown\";\n }\n\n // Prevent infinite loops in recursive functions\n if (executionOrderCheckedNodes.has(path.node)) continue;\n executionOrderCheckedNodes.add(path.node);\n try {\n const status = _guessExecutionStatusRelativeToCached(base, path, cache);\n\n if (allStatus && allStatus !== status) {\n return \"unknown\";\n } else {\n allStatus = status;\n }\n } finally {\n executionOrderCheckedNodes.delete(path.node);\n }\n }\n\n return allStatus;\n}\n\nfunction _guessExecutionStatusRelativeToDifferentFunctionsCached(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n let nodeMap = cache.get(base.node);\n if (!nodeMap) {\n cache.set(base.node, (nodeMap = new Map()));\n } else if (nodeMap.has(target.node)) {\n return nodeMap.get(target.node);\n }\n\n const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(\n base,\n target,\n cache,\n );\n\n nodeMap.set(target.node, result);\n return result;\n}\n\n/**\n * Resolve a \"pointer\" `NodePath` to it's absolute path.\n */\nexport function resolve(\n this: NodePath,\n dangerous?: boolean,\n resolved?: NodePath[],\n) {\n return this._resolve(dangerous, resolved) || this;\n}\n\nexport function _resolve(\n this: NodePath,\n dangerous?: boolean,\n resolved?: NodePath[],\n): NodePath | undefined | null {\n // detect infinite recursion\n // todo: possibly have a max length on this just to be safe\n if (resolved && resolved.indexOf(this) >= 0) return;\n\n // we store all the paths we've \"resolved\" in this array to prevent infinite recursion\n resolved = resolved || [];\n resolved.push(this);\n\n if (this.isVariableDeclarator()) {\n if (this.get(\"id\").isIdentifier()) {\n return this.get(\"init\").resolve(dangerous, resolved);\n } else {\n // otherwise it's a request for a pattern and that's a bit more tricky\n }\n } else if (this.isReferencedIdentifier()) {\n const binding = this.scope.getBinding(this.node.name);\n if (!binding) return;\n\n // reassigned so we can't really resolve it\n if (!binding.constant) return;\n\n // todo - lookup module in dependency graph\n if (binding.kind === \"module\") return;\n\n if (binding.path !== this) {\n const ret = binding.path.resolve(dangerous, resolved);\n // If the identifier resolves to parent node then we can't really resolve it.\n if (this.find(parent => parent.node === ret.node)) return;\n return ret;\n }\n } else if (this.isTypeCastExpression()) {\n // @ ts-ignore todo: babel-types\n return this.get(\"expression\").resolve(dangerous, resolved);\n } else if (dangerous && this.isMemberExpression()) {\n // this is dangerous, as non-direct target assignments will mutate it's state\n // making this resolution inaccurate\n\n const targetKey = this.toComputedKey();\n if (!isLiteral(targetKey)) return;\n\n // @ts-expect-error todo(flow->ts): NullLiteral\n const targetName = targetKey.value;\n\n const target = this.get(\"object\").resolve(dangerous, resolved);\n\n if (target.isObjectExpression()) {\n const props = target.get(\"properties\");\n for (const prop of props as any[]) {\n if (!prop.isProperty()) continue;\n\n const key = prop.get(\"key\");\n\n // { foo: obj }\n let match =\n prop.isnt(\"computed\") && key.isIdentifier({ name: targetName });\n\n // { \"foo\": \"obj\" } or { [\"foo\"]: \"obj\" }\n match = match || key.isLiteral({ value: targetName });\n\n if (match) return prop.get(\"value\").resolve(dangerous, resolved);\n }\n } else if (target.isArrayExpression() && !isNaN(+targetName)) {\n const elems = target.get(\"elements\");\n const elem = elems[targetName];\n if (elem) return elem.resolve(dangerous, resolved);\n }\n }\n}\n\nexport function isConstantExpression(this: NodePath): boolean {\n if (this.isIdentifier()) {\n const binding = this.scope.getBinding(this.node.name);\n if (!binding) return false;\n return binding.constant;\n }\n\n if (this.isLiteral()) {\n if (this.isRegExpLiteral()) {\n return false;\n }\n\n if (this.isTemplateLiteral()) {\n return this.get(\"expressions\").every(expression =>\n expression.isConstantExpression(),\n );\n }\n\n return true;\n }\n\n if (this.isUnaryExpression()) {\n if (this.node.operator !== \"void\") {\n return false;\n }\n\n return this.get(\"argument\").isConstantExpression();\n }\n\n if (this.isBinaryExpression()) {\n return (\n this.get(\"left\").isConstantExpression() &&\n this.get(\"right\").isConstantExpression()\n );\n }\n\n return false;\n}\n\nexport function isInStrictMode(this: NodePath) {\n const start = this.isProgram() ? this : this.parentPath;\n\n const strictParent = start.find(path => {\n if (path.isProgram({ sourceType: \"module\" })) return true;\n\n if (path.isClass()) return true;\n\n if (\n path.isArrowFunctionExpression() &&\n !path.get(\"body\").isBlockStatement()\n ) {\n return false;\n }\n\n let body: t.BlockStatement | t.Program;\n if (path.isFunction()) {\n body = path.node.body as t.BlockStatement;\n } else if (path.isProgram()) {\n body = path.node;\n } else {\n return false;\n }\n\n for (const directive of body.directives) {\n if (directive.value.value === \"use strict\") {\n return true;\n }\n }\n });\n\n return !!strictParent;\n}\n"],"mappings":";;;;;;;;;;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A7C;EAEA,MAAMyH,YAAY,GAAG7E,KAAK,CAACuC,IAAN,CAAW5E,IAAI,IAAI;IACtC,IAAIA,IAAI,CAACI,SAAL,CAAe;MAAE+G,UAAU,EAAE;IAAd,CAAf,CAAJ,EAA8C,OAAO,IAAP;IAE9C,IAAInH,IAAI,CAACoH,OAAL,EAAJ,EAAoB,OAAO,IAAP;;IAEpB,IACEpH,IAAI,CAACH,yBAAL,MACA,CAACG,IAAI,CAACoB,GAAL,CAAS,MAAT,EAAiBrD,gBAAjB,EAFH,EAGE;MACA,OAAO,KAAP;IACD;;IAED,IAAIsJ,IAAJ;;IACA,IAAIrH,IAAI,CAACG,UAAL,EAAJ,EAAuB;MACrBkH,IAAI,GAAGrH,IAAI,CAACvB,IAAL,CAAU4I,IAAjB;IACD,CAFD,MAEO,IAAIrH,IAAI,CAACI,SAAL,EAAJ,EAAsB;MAC3BiH,IAAI,GAAGrH,IAAI,CAACvB,IAAZ;IACD,CAFM,MAEA;MACL,OAAO,KAAP;IACD;;IAED,KAAK,MAAM6I,SAAX,IAAwBD,IAAI,CAACE,UAA7B,EAAyC;MACvC,IAAID,SAAS,CAACjI,KAAV,CAAgBA,KAAhB,KAA0B,YAA9B,EAA4C;QAC1C,OAAO,IAAP;MACD;IACF;EACF,CA1BoB,CAArB;EA4BA,OAAO,CAAC,CAAC6H,YAAT;AACD"}
1
+ {"version":3,"names":["STATEMENT_OR_BLOCK_KEYS","VISITOR_KEYS","isBlockStatement","isExpression","isIdentifier","isLiteral","isStringLiteral","isType","matchesPattern","_matchesPattern","pattern","allowPartial","node","has","key","val","Array","isArray","length","isStatic","scope","is","isnt","equals","value","isNodeType","type","canHaveVariableDeclarationOrExpression","parentPath","isFor","canSwapBetweenExpressionAndStatement","replacement","isArrowFunctionExpression","isCompletionRecord","allowInsideFunction","path","first","container","isFunction","isProgram","isDoExpression","isStatementOrBlock","isLabeledStatement","includes","referencesImport","moduleSource","importName","isReferencedIdentifier","isJSXMemberExpression","property","name","isMemberExpression","isOptionalMemberExpression","computed","object","get","binding","getBinding","kind","parent","isImportDeclaration","source","isImportDefaultSpecifier","isImportNamespaceSpecifier","isImportSpecifier","imported","getSource","end","code","hub","getCode","slice","start","willIMaybeExecuteBefore","target","_guessExecutionStatusRelativeTo","getOuterFunction","getFunctionParent","getProgramParent","isExecutionUncertain","isExecutionUncertainInList","paths","maxIndex","i","parentKey","_guessExecutionStatusRelativeToCached","Map","base","cache","funcParent","this","_guessExecutionStatusRelativeToDifferentFunctionsCached","getAncestry","indexOf","commonPath","commonIndex","Error","divergence","listKey","keys","keyPosition","executionOrderCheckedNodes","Set","_guessExecutionStatusRelativeToDifferentFunctionsInternal","isFunctionDeclaration","isExportDeclaration","id","references","referencePaths","allStatus","childOfFunction","find","isCallExpression","add","status","delete","nodeMap","set","result","resolve","dangerous","resolved","_resolve","push","isVariableDeclarator","constant","ret","isTypeCastExpression","targetKey","toComputedKey","targetName","isObjectExpression","props","prop","isProperty","match","isArrayExpression","isNaN","elems","elem","isConstantExpression","isRegExpLiteral","isTemplateLiteral","every","expression","isUnaryExpression","operator","isBinaryExpression","isInStrictMode","strictParent","sourceType","isClass","body","directive","directives"],"sources":["../../src/path/introspection.ts"],"sourcesContent":["// This file contains methods responsible for introspecting the current path for certain values.\n\nimport type NodePath from \"./index\";\nimport {\n STATEMENT_OR_BLOCK_KEYS,\n VISITOR_KEYS,\n isBlockStatement,\n isExpression,\n isIdentifier,\n isLiteral,\n isStringLiteral,\n isType,\n matchesPattern as _matchesPattern,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\n/**\n * Match the current node if it matches the provided `pattern`.\n *\n * For example, given the match `React.createClass` it would match the\n * parsed nodes of `React.createClass` and `React[\"createClass\"]`.\n */\n\nexport function matchesPattern(\n this: NodePath,\n pattern: string,\n allowPartial?: boolean,\n): boolean {\n return _matchesPattern(this.node, pattern, allowPartial);\n}\n\n/**\n * Check whether we have the input `key`. If the `key` references an array then we check\n * if the array has any items, otherwise we just check if it's falsy.\n */\n\nexport function has<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n): boolean {\n const val = this.node && this.node[key];\n if (val && Array.isArray(val)) {\n return !!val.length;\n } else {\n return !!val;\n }\n}\n\n/**\n * Description\n */\n\nexport function isStatic(this: NodePath): boolean {\n return this.scope.isStatic(this.node);\n}\n\n/**\n * Alias of `has`.\n */\n\nexport const is = has;\n\n/**\n * Opposite of `has`.\n */\n\nexport function isnt<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n): boolean {\n return !this.has(key);\n}\n\n/**\n * Check whether the path node `key` strict equals `value`.\n */\n\nexport function equals<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n value: any,\n): boolean {\n return this.node[key] === value;\n}\n\n/**\n * Check the type against our stored internal type of the node. This is handy when a node has\n * been removed yet we still internally know the type and need it to calculate node replacement.\n */\n\nexport function isNodeType(this: NodePath, type: string): boolean {\n return isType(this.type, type);\n}\n\n/**\n * This checks whether or not we're in one of the following positions:\n *\n * for (KEY in right);\n * for (KEY;;);\n *\n * This is because these spots allow VariableDeclarations AND normal expressions so we need\n * to tell the path replacement that it's ok to replace this with an expression.\n */\n\nexport function canHaveVariableDeclarationOrExpression(this: NodePath) {\n return (\n (this.key === \"init\" || this.key === \"left\") && this.parentPath.isFor()\n );\n}\n\n/**\n * This checks whether we are swapping an arrow function's body between an\n * expression and a block statement (or vice versa).\n *\n * This is because arrow functions may implicitly return an expression, which\n * is the same as containing a block statement.\n */\n\nexport function canSwapBetweenExpressionAndStatement(\n this: NodePath,\n replacement: t.Node,\n): boolean {\n if (this.key !== \"body\" || !this.parentPath.isArrowFunctionExpression()) {\n return false;\n }\n\n if (this.isExpression()) {\n return isBlockStatement(replacement);\n } else if (this.isBlockStatement()) {\n return isExpression(replacement);\n }\n\n return false;\n}\n\n/**\n * Check whether the current path references a completion record\n */\n\nexport function isCompletionRecord(\n this: NodePath,\n allowInsideFunction?: boolean,\n): boolean {\n let path = this;\n let first = true;\n\n do {\n const { type, container } = path;\n\n // we're in a function so can't be a completion record\n if (!first && (path.isFunction() || type === \"StaticBlock\")) {\n return !!allowInsideFunction;\n }\n\n first = false;\n\n // check to see if we're the last item in the container and if we are\n // we're a completion record!\n if (Array.isArray(container) && path.key !== container.length - 1) {\n return false;\n }\n } while (\n (path = path.parentPath) &&\n !path.isProgram() &&\n !path.isDoExpression()\n );\n\n return true;\n}\n\n/**\n * Check whether or not the current `key` allows either a single statement or block statement\n * so we can explode it if necessary.\n */\n\nexport function isStatementOrBlock(this: NodePath): boolean {\n if (\n this.parentPath.isLabeledStatement() ||\n isBlockStatement(this.container)\n ) {\n return false;\n } else {\n return STATEMENT_OR_BLOCK_KEYS.includes(this.key as string);\n }\n}\n\n/**\n * Check if the currently assigned path references the `importName` of `moduleSource`.\n */\n\nexport function referencesImport(\n this: NodePath,\n moduleSource: string,\n importName: string,\n): boolean {\n if (!this.isReferencedIdentifier()) {\n if (\n (this.isJSXMemberExpression() &&\n this.node.property.name === importName) ||\n ((this.isMemberExpression() || this.isOptionalMemberExpression()) &&\n (this.node.computed\n ? isStringLiteral(this.node.property, { value: importName })\n : (this.node.property as t.Identifier).name === importName))\n ) {\n const object = (\n this as NodePath<t.MemberExpression | t.OptionalMemberExpression>\n ).get(\"object\");\n return (\n object.isReferencedIdentifier() &&\n object.referencesImport(moduleSource, \"*\")\n );\n }\n\n return false;\n }\n\n const binding = this.scope.getBinding((this.node as t.Identifier).name);\n if (!binding || binding.kind !== \"module\") return false;\n\n const path = binding.path;\n const parent = path.parentPath;\n if (!parent.isImportDeclaration()) return false;\n\n // check moduleSource\n if (parent.node.source.value === moduleSource) {\n if (!importName) return true;\n } else {\n return false;\n }\n\n if (path.isImportDefaultSpecifier() && importName === \"default\") {\n return true;\n }\n\n if (path.isImportNamespaceSpecifier() && importName === \"*\") {\n return true;\n }\n\n if (\n path.isImportSpecifier() &&\n isIdentifier(path.node.imported, { name: importName })\n ) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Get the source code associated with this node.\n */\n\nexport function getSource(this: NodePath): string {\n const node = this.node;\n if (node.end) {\n const code = this.hub.getCode();\n if (code) return code.slice(node.start, node.end);\n }\n return \"\";\n}\n\nexport function willIMaybeExecuteBefore(\n this: NodePath,\n target: NodePath,\n): boolean {\n return this._guessExecutionStatusRelativeTo(target) !== \"after\";\n}\n\nfunction getOuterFunction(path: NodePath) {\n return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path;\n}\n\nfunction isExecutionUncertain(type: t.Node[\"type\"], key: string) {\n switch (type) {\n // a && FOO\n // a || FOO\n case \"LogicalExpression\":\n return key === \"right\";\n\n // a ? FOO : FOO\n // if (a) FOO; else FOO;\n case \"ConditionalExpression\":\n case \"IfStatement\":\n return key === \"consequent\" || key === \"alternate\";\n\n // while (a) FOO;\n case \"WhileStatement\":\n case \"DoWhileStatement\":\n case \"ForInStatement\":\n case \"ForOfStatement\":\n return key === \"body\";\n\n // for (a; b; FOO) FOO;\n case \"ForStatement\":\n return key === \"body\" || key === \"update\";\n\n // switch (a) { FOO }\n case \"SwitchStatement\":\n return key === \"cases\";\n\n // try { a } catch FOO finally { b }\n case \"TryStatement\":\n return key === \"handler\";\n\n // var [ x = FOO ]\n case \"AssignmentPattern\":\n return key === \"right\";\n\n // a?.[FOO]\n case \"OptionalMemberExpression\":\n return key === \"property\";\n\n // a?.(FOO)\n case \"OptionalCallExpression\":\n return key === \"arguments\";\n\n default:\n return false;\n }\n}\n\nfunction isExecutionUncertainInList(paths: NodePath[], maxIndex: number) {\n for (let i = 0; i < maxIndex; i++) {\n const path = paths[i];\n if (isExecutionUncertain(path.parent.type, path.parentKey)) {\n return true;\n }\n }\n return false;\n}\n\n// TODO (Babel 8)\n// This can be { before: boolean, after: boolean, unknown: boolean }.\n// This allows transforms like the tdz one to treat cases when the status\n// is both before and unknown/after like if it were before.\ntype RelativeExecutionStatus = \"before\" | \"after\" | \"unknown\";\n\ntype ExecutionStatusCache = Map<t.Node, Map<t.Node, RelativeExecutionStatus>>;\n\n/**\n * Given a `target` check the execution status of it relative to the current path.\n *\n * \"Execution status\" simply refers to where or not we **think** this will execute\n * before or after the input `target` element.\n */\n\nexport function _guessExecutionStatusRelativeTo(\n this: NodePath,\n target: NodePath,\n): RelativeExecutionStatus {\n return _guessExecutionStatusRelativeToCached(this, target, new Map());\n}\n\nfunction _guessExecutionStatusRelativeToCached(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n // check if the two paths are in different functions, we can't track execution of these\n const funcParent = {\n this: getOuterFunction(base),\n target: getOuterFunction(target),\n };\n\n // here we check the `node` equality as sometimes we may have different paths for the\n // same node due to path thrashing\n if (funcParent.target.node !== funcParent.this.node) {\n return _guessExecutionStatusRelativeToDifferentFunctionsCached(\n base,\n funcParent.target,\n cache,\n );\n }\n\n const paths = {\n target: target.getAncestry(),\n this: base.getAncestry(),\n };\n\n // If this is an ancestor of the target path,\n // e.g. f(g); where this is f and target is g.\n if (paths.target.indexOf(base) >= 0) return \"after\";\n if (paths.this.indexOf(target) >= 0) return \"before\";\n\n // get ancestor where the branches intersect\n let commonPath;\n const commonIndex = { target: 0, this: 0 };\n\n while (!commonPath && commonIndex.this < paths.this.length) {\n const path = paths.this[commonIndex.this];\n commonIndex.target = paths.target.indexOf(path);\n if (commonIndex.target >= 0) {\n commonPath = path;\n } else {\n commonIndex.this++;\n }\n }\n\n if (!commonPath) {\n throw new Error(\n \"Internal Babel error - The two compared nodes\" +\n \" don't appear to belong to the same program.\",\n );\n }\n\n if (\n isExecutionUncertainInList(paths.this, commonIndex.this - 1) ||\n isExecutionUncertainInList(paths.target, commonIndex.target - 1)\n ) {\n return \"unknown\";\n }\n\n const divergence = {\n this: paths.this[commonIndex.this - 1],\n target: paths.target[commonIndex.target - 1],\n };\n\n // container list so let's see which one is after the other\n // e.g. [ THIS, TARGET ]\n if (\n divergence.target.listKey &&\n divergence.this.listKey &&\n divergence.target.container === divergence.this.container\n ) {\n return divergence.target.key > divergence.this.key ? \"before\" : \"after\";\n }\n\n // otherwise we're associated by a parent node, check which key comes before the other\n const keys = VISITOR_KEYS[commonPath.type];\n const keyPosition = {\n this: keys.indexOf(divergence.this.parentKey as string),\n target: keys.indexOf(divergence.target.parentKey as string),\n };\n return keyPosition.target > keyPosition.this ? \"before\" : \"after\";\n}\n\n// Used to avoid infinite recursion in cases like\n// function f() { if (false) f(); }\n// f();\n// It also works with indirect recursion.\nconst executionOrderCheckedNodes = new Set();\n\nfunction _guessExecutionStatusRelativeToDifferentFunctionsInternal(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n if (\n !target.isFunctionDeclaration() ||\n target.parentPath.isExportDeclaration()\n ) {\n return \"unknown\";\n }\n\n // so we're in a completely different function, if this is a function declaration\n // then we can be a bit smarter and handle cases where the function is either\n // a. not called at all (part of an export)\n // b. called directly\n const binding = target.scope.getBinding(target.node.id.name);\n\n // no references!\n if (!binding.references) return \"before\";\n\n const referencePaths: Array<NodePath> = binding.referencePaths;\n\n let allStatus;\n\n // verify that all the calls have the same execution status\n for (const path of referencePaths) {\n // if a reference is a child of the function we're checking against then we can\n // safely ignore it\n const childOfFunction = !!path.find(path => path.node === target.node);\n if (childOfFunction) continue;\n\n if (path.key !== \"callee\" || !path.parentPath.isCallExpression()) {\n // This function is passed as a reference, so we don't\n // know when it will be called.\n return \"unknown\";\n }\n\n // Prevent infinite loops in recursive functions\n if (executionOrderCheckedNodes.has(path.node)) continue;\n executionOrderCheckedNodes.add(path.node);\n try {\n const status = _guessExecutionStatusRelativeToCached(base, path, cache);\n\n if (allStatus && allStatus !== status) {\n return \"unknown\";\n } else {\n allStatus = status;\n }\n } finally {\n executionOrderCheckedNodes.delete(path.node);\n }\n }\n\n return allStatus;\n}\n\nfunction _guessExecutionStatusRelativeToDifferentFunctionsCached(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n let nodeMap = cache.get(base.node);\n if (!nodeMap) {\n cache.set(base.node, (nodeMap = new Map()));\n } else if (nodeMap.has(target.node)) {\n return nodeMap.get(target.node);\n }\n\n const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(\n base,\n target,\n cache,\n );\n\n nodeMap.set(target.node, result);\n return result;\n}\n\n/**\n * Resolve a \"pointer\" `NodePath` to it's absolute path.\n */\nexport function resolve(\n this: NodePath,\n dangerous?: boolean,\n resolved?: NodePath[],\n) {\n return this._resolve(dangerous, resolved) || this;\n}\n\nexport function _resolve(\n this: NodePath,\n dangerous?: boolean,\n resolved?: NodePath[],\n): NodePath | undefined | null {\n // detect infinite recursion\n // todo: possibly have a max length on this just to be safe\n if (resolved && resolved.indexOf(this) >= 0) return;\n\n // we store all the paths we've \"resolved\" in this array to prevent infinite recursion\n resolved = resolved || [];\n resolved.push(this);\n\n if (this.isVariableDeclarator()) {\n if (this.get(\"id\").isIdentifier()) {\n return this.get(\"init\").resolve(dangerous, resolved);\n } else {\n // otherwise it's a request for a pattern and that's a bit more tricky\n }\n } else if (this.isReferencedIdentifier()) {\n const binding = this.scope.getBinding(this.node.name);\n if (!binding) return;\n\n // reassigned so we can't really resolve it\n if (!binding.constant) return;\n\n // todo - lookup module in dependency graph\n if (binding.kind === \"module\") return;\n\n if (binding.path !== this) {\n const ret = binding.path.resolve(dangerous, resolved);\n // If the identifier resolves to parent node then we can't really resolve it.\n if (this.find(parent => parent.node === ret.node)) return;\n return ret;\n }\n } else if (this.isTypeCastExpression()) {\n // @ ts-ignore todo: babel-types\n return this.get(\"expression\").resolve(dangerous, resolved);\n } else if (dangerous && this.isMemberExpression()) {\n // this is dangerous, as non-direct target assignments will mutate it's state\n // making this resolution inaccurate\n\n const targetKey = this.toComputedKey();\n if (!isLiteral(targetKey)) return;\n\n // @ts-expect-error todo(flow->ts): NullLiteral\n const targetName = targetKey.value;\n\n const target = this.get(\"object\").resolve(dangerous, resolved);\n\n if (target.isObjectExpression()) {\n const props = target.get(\"properties\");\n for (const prop of props as any[]) {\n if (!prop.isProperty()) continue;\n\n const key = prop.get(\"key\");\n\n // { foo: obj }\n let match =\n prop.isnt(\"computed\") && key.isIdentifier({ name: targetName });\n\n // { \"foo\": \"obj\" } or { [\"foo\"]: \"obj\" }\n match = match || key.isLiteral({ value: targetName });\n\n if (match) return prop.get(\"value\").resolve(dangerous, resolved);\n }\n } else if (target.isArrayExpression() && !isNaN(+targetName)) {\n const elems = target.get(\"elements\");\n const elem = elems[targetName];\n if (elem) return elem.resolve(dangerous, resolved);\n }\n }\n}\n\nexport function isConstantExpression(this: NodePath): boolean {\n if (this.isIdentifier()) {\n const binding = this.scope.getBinding(this.node.name);\n if (!binding) return false;\n return binding.constant;\n }\n\n if (this.isLiteral()) {\n if (this.isRegExpLiteral()) {\n return false;\n }\n\n if (this.isTemplateLiteral()) {\n return this.get(\"expressions\").every(expression =>\n expression.isConstantExpression(),\n );\n }\n\n return true;\n }\n\n if (this.isUnaryExpression()) {\n if (this.node.operator !== \"void\") {\n return false;\n }\n\n return this.get(\"argument\").isConstantExpression();\n }\n\n if (this.isBinaryExpression()) {\n const { operator } = this.node;\n return (\n operator !== \"in\" &&\n operator !== \"instanceof\" &&\n this.get(\"left\").isConstantExpression() &&\n this.get(\"right\").isConstantExpression()\n );\n }\n\n return false;\n}\n\nexport function isInStrictMode(this: NodePath) {\n const start = this.isProgram() ? this : this.parentPath;\n\n const strictParent = start.find(path => {\n if (path.isProgram({ sourceType: \"module\" })) return true;\n\n if (path.isClass()) return true;\n\n if (\n path.isArrowFunctionExpression() &&\n !path.get(\"body\").isBlockStatement()\n ) {\n return false;\n }\n\n let body: t.BlockStatement | t.Program;\n if (path.isFunction()) {\n body = path.node.body as t.BlockStatement;\n } else if (path.isProgram()) {\n body = path.node;\n } else {\n return false;\n }\n\n for (const directive of body.directives) {\n if (directive.value.value === \"use strict\") {\n return true;\n }\n }\n });\n\n return !!strictParent;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA;AAUsB;EATpBA,uBAAuB;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@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _t = require("@babel/types");
9
-
10
8
  var _t2 = _t;
11
9
  const {
12
10
  react
@@ -25,13 +23,11 @@ const referenceVisitor = {
25
23
 
26
24
  if (path.node.name === "this") {
27
25
  let scope = path.scope;
28
-
29
26
  do {
30
27
  if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
31
28
  break;
32
29
  }
33
30
  } while (scope = scope.parent);
34
-
35
31
  if (scope) state.breakOnScopePaths.push(scope.path);
36
32
  }
37
33
 
@@ -49,9 +45,7 @@ const referenceVisitor = {
49
45
  if (binding !== state.scope.getBinding(path.node.name)) return;
50
46
  state.bindings[path.node.name] = binding;
51
47
  }
52
-
53
48
  };
54
-
55
49
  class PathHoister {
56
50
  constructor(path, scope) {
57
51
  this.breakOnScopePaths = void 0;
@@ -73,18 +67,15 @@ class PathHoister {
73
67
  isCompatibleScope(scope) {
74
68
  for (const key of Object.keys(this.bindings)) {
75
69
  const binding = this.bindings[key];
76
-
77
70
  if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
78
71
  return false;
79
72
  }
80
73
  }
81
-
82
74
  return true;
83
75
  }
84
76
 
85
77
  getCompatibleScopes() {
86
78
  let scope = this.path.scope;
87
-
88
79
  do {
89
80
  if (this.isCompatibleScope(scope)) {
90
81
  this.scopes.push(scope);
@@ -97,10 +88,8 @@ class PathHoister {
97
88
  }
98
89
  } while (scope = scope.parent);
99
90
  }
100
-
101
91
  getAttachmentPath() {
102
92
  let path = this._getAttachmentPath();
103
-
104
93
  if (!path) return;
105
94
  let targetScope = path.scope;
106
95
 
@@ -131,20 +120,17 @@ class PathHoister {
131
120
  }
132
121
  }
133
122
  }
134
-
135
123
  return path;
136
124
  }
137
-
138
125
  _getAttachmentPath() {
139
126
  const scopes = this.scopes;
140
127
  const scope = scopes.pop();
141
128
  if (!scope) return;
142
-
143
129
  if (scope.path.isFunction()) {
144
130
  if (this.hasOwnParamBindings(scope)) {
145
131
  if (this.scope === scope) return;
146
- const bodies = scope.path.get("body").get("body");
147
132
 
133
+ const bodies = scope.path.get("body").get("body");
148
134
  for (let i = 0; i < bodies.length; i++) {
149
135
  if (bodies[i].node._blockHoist) continue;
150
136
  return bodies[i];
@@ -156,7 +142,6 @@ class PathHoister {
156
142
  return this.getNextScopeAttachmentParent();
157
143
  }
158
144
  }
159
-
160
145
  getNextScopeAttachmentParent() {
161
146
  const scope = this.scopes.pop();
162
147
  if (scope) return this.getAttachmentParentForPath(scope.path);
@@ -164,7 +149,9 @@ class PathHoister {
164
149
 
165
150
  getAttachmentParentForPath(path) {
166
151
  do {
167
- if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
152
+ if (
153
+ !path.parentPath ||
154
+ Array.isArray(path.container) && path.isStatement()) {
168
155
  return path;
169
156
  }
170
157
  } while (path = path.parentPath);
@@ -176,33 +163,30 @@ class PathHoister {
176
163
  const binding = this.bindings[name];
177
164
  if (binding.kind === "param" && binding.constant) return true;
178
165
  }
179
-
180
166
  return false;
181
167
  }
182
-
183
168
  run() {
184
169
  this.path.traverse(referenceVisitor, this);
185
170
  if (this.mutableBinding) return;
186
171
  this.getCompatibleScopes();
187
172
  const attachTo = this.getAttachmentPath();
188
173
  if (!attachTo) return;
174
+
189
175
  if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
176
+
190
177
  let uid = attachTo.scope.generateUidIdentifier("ref");
178
+
191
179
  const declarator = variableDeclarator(uid, this.path.node);
192
180
  const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
193
181
  const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : variableDeclaration("var", [declarator])]);
194
182
  const parent = this.path.parentPath;
195
-
196
183
  if (parent.isJSXElement() && this.path.container === parent.node.children) {
197
184
  uid = jsxExpressionContainer(uid);
198
185
  }
199
-
200
186
  this.path.replaceWith(cloneNode(uid));
201
187
  return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
202
188
  }
203
-
204
189
  }
205
-
206
190
  exports.default = PathHoister;
207
191
 
208
192
  //# sourceMappingURL=hoister.js.map