@babel/traverse 7.17.9 → 7.23.4

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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/lib/cache.js +27 -9
  3. package/lib/cache.js.map +1 -0
  4. package/lib/context.js +9 -31
  5. package/lib/context.js.map +1 -0
  6. package/lib/hub.js +2 -6
  7. package/lib/hub.js.map +1 -0
  8. package/lib/index.js +18 -35
  9. package/lib/index.js.map +1 -0
  10. package/lib/path/ancestry.js +3 -42
  11. package/lib/path/ancestry.js.map +1 -0
  12. package/lib/path/comments.js +23 -11
  13. package/lib/path/comments.js.map +1 -0
  14. package/lib/path/context.js +24 -65
  15. package/lib/path/context.js.map +1 -0
  16. package/lib/path/conversion.js +37 -100
  17. package/lib/path/conversion.js.map +1 -0
  18. package/lib/path/evaluation.js +69 -123
  19. package/lib/path/evaluation.js.map +1 -0
  20. package/lib/path/family.js +5 -76
  21. package/lib/path/family.js.map +1 -0
  22. package/lib/path/index.js +28 -96
  23. package/lib/path/index.js.map +1 -0
  24. package/lib/path/inference/index.js +26 -33
  25. package/lib/path/inference/index.js.map +1 -0
  26. package/lib/path/inference/inferer-reference.js +6 -61
  27. package/lib/path/inference/inferer-reference.js.map +1 -0
  28. package/lib/path/inference/inferers.js +32 -86
  29. package/lib/path/inference/inferers.js.map +1 -0
  30. package/lib/path/inference/util.js +30 -0
  31. package/lib/path/inference/util.js.map +1 -0
  32. package/lib/path/introspection.js +55 -107
  33. package/lib/path/introspection.js.map +1 -0
  34. package/lib/path/lib/hoister.js +2 -37
  35. package/lib/path/lib/hoister.js.map +1 -0
  36. package/lib/path/lib/removal-hooks.js +4 -5
  37. package/lib/path/lib/removal-hooks.js.map +1 -0
  38. package/lib/path/lib/virtual-types-validator.js +161 -0
  39. package/lib/path/lib/virtual-types-validator.js.map +1 -0
  40. package/lib/path/lib/virtual-types.js +20 -224
  41. package/lib/path/lib/virtual-types.js.map +1 -0
  42. package/lib/path/modification.js +17 -61
  43. package/lib/path/modification.js.map +1 -0
  44. package/lib/path/removal.js +9 -22
  45. package/lib/path/removal.js.map +1 -0
  46. package/lib/path/replacement.js +80 -76
  47. package/lib/path/replacement.js.map +1 -0
  48. package/lib/scope/binding.js +20 -12
  49. package/lib/scope/binding.js.map +1 -0
  50. package/lib/scope/index.js +117 -247
  51. package/lib/scope/index.js.map +1 -0
  52. package/lib/scope/lib/renamer.js +41 -74
  53. package/lib/scope/lib/renamer.js.map +1 -0
  54. package/lib/traverse-node.js +10 -11
  55. package/lib/traverse-node.js.map +1 -0
  56. package/lib/types.js +1 -3
  57. package/lib/types.js.map +1 -0
  58. package/lib/visitors.js +62 -83
  59. package/lib/visitors.js.map +1 -0
  60. package/package.json +13 -11
  61. package/lib/path/generated/asserts.js +0 -5
  62. package/lib/path/generated/validators.js +0 -5
  63. package/lib/path/generated/virtual-types.js +0 -3
  64. package/scripts/generators/asserts.js +0 -25
  65. package/scripts/generators/validators.js +0 -42
  66. package/scripts/generators/virtual-types.js +0 -24
  67. package/scripts/package.json +0 -1
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
7
- exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
8
7
  exports._resolve = _resolve;
9
8
  exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
10
9
  exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
@@ -23,9 +22,7 @@ exports.matchesPattern = matchesPattern;
23
22
  exports.referencesImport = referencesImport;
24
23
  exports.resolve = resolve;
25
24
  exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
26
-
27
25
  var _t = require("@babel/types");
28
-
29
26
  const {
30
27
  STATEMENT_OR_BLOCK_KEYS,
31
28
  VISITOR_KEYS,
@@ -37,79 +34,62 @@ const {
37
34
  isType,
38
35
  matchesPattern: _matchesPattern
39
36
  } = _t;
40
-
41
37
  function matchesPattern(pattern, allowPartial) {
42
38
  return _matchesPattern(this.node, pattern, allowPartial);
43
39
  }
44
-
45
40
  function has(key) {
46
41
  const val = this.node && this.node[key];
47
-
48
42
  if (val && Array.isArray(val)) {
49
43
  return !!val.length;
50
44
  } else {
51
45
  return !!val;
52
46
  }
53
47
  }
54
-
55
48
  function isStatic() {
56
49
  return this.scope.isStatic(this.node);
57
50
  }
58
-
59
- const is = has;
60
- exports.is = is;
61
-
51
+ const is = exports.is = has;
62
52
  function isnt(key) {
63
53
  return !this.has(key);
64
54
  }
65
-
66
55
  function equals(key, value) {
67
56
  return this.node[key] === value;
68
57
  }
69
-
70
58
  function isNodeType(type) {
71
59
  return isType(this.type, type);
72
60
  }
73
-
74
61
  function canHaveVariableDeclarationOrExpression() {
75
62
  return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
76
63
  }
77
-
78
64
  function canSwapBetweenExpressionAndStatement(replacement) {
79
65
  if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
80
66
  return false;
81
67
  }
82
-
83
68
  if (this.isExpression()) {
84
69
  return isBlockStatement(replacement);
85
70
  } else if (this.isBlockStatement()) {
86
71
  return isExpression(replacement);
87
72
  }
88
-
89
73
  return false;
90
74
  }
91
-
92
75
  function isCompletionRecord(allowInsideFunction) {
93
76
  let path = this;
94
77
  let first = true;
95
-
96
78
  do {
97
- const container = path.container;
98
-
99
- if (path.isFunction() && !first) {
79
+ const {
80
+ type,
81
+ container
82
+ } = path;
83
+ if (!first && (path.isFunction() || type === "StaticBlock")) {
100
84
  return !!allowInsideFunction;
101
85
  }
102
-
103
86
  first = false;
104
-
105
87
  if (Array.isArray(container) && path.key !== container.length - 1) {
106
88
  return false;
107
89
  }
108
- } while ((path = path.parentPath) && !path.isProgram());
109
-
90
+ } while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
110
91
  return true;
111
92
  }
112
-
113
93
  function isStatementOrBlock() {
114
94
  if (this.parentPath.isLabeledStatement() || isBlockStatement(this.container)) {
115
95
  return false;
@@ -117,7 +97,6 @@ function isStatementOrBlock() {
117
97
  return STATEMENT_OR_BLOCK_KEYS.includes(this.key);
118
98
  }
119
99
  }
120
-
121
100
  function referencesImport(moduleSource, importName) {
122
101
  if (!this.isReferencedIdentifier()) {
123
102
  if (this.isJSXMemberExpression() && this.node.property.name === importName || (this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
@@ -126,158 +105,127 @@ function referencesImport(moduleSource, importName) {
126
105
  const object = this.get("object");
127
106
  return object.isReferencedIdentifier() && object.referencesImport(moduleSource, "*");
128
107
  }
129
-
130
108
  return false;
131
109
  }
132
-
133
110
  const binding = this.scope.getBinding(this.node.name);
134
111
  if (!binding || binding.kind !== "module") return false;
135
112
  const path = binding.path;
136
113
  const parent = path.parentPath;
137
114
  if (!parent.isImportDeclaration()) return false;
138
-
139
115
  if (parent.node.source.value === moduleSource) {
140
116
  if (!importName) return true;
141
117
  } else {
142
118
  return false;
143
119
  }
144
-
145
120
  if (path.isImportDefaultSpecifier() && importName === "default") {
146
121
  return true;
147
122
  }
148
-
149
123
  if (path.isImportNamespaceSpecifier() && importName === "*") {
150
124
  return true;
151
125
  }
152
-
153
126
  if (path.isImportSpecifier() && isIdentifier(path.node.imported, {
154
127
  name: importName
155
128
  })) {
156
129
  return true;
157
130
  }
158
-
159
131
  return false;
160
132
  }
161
-
162
133
  function getSource() {
163
134
  const node = this.node;
164
-
165
135
  if (node.end) {
166
136
  const code = this.hub.getCode();
167
137
  if (code) return code.slice(node.start, node.end);
168
138
  }
169
-
170
139
  return "";
171
140
  }
172
-
173
141
  function willIMaybeExecuteBefore(target) {
174
142
  return this._guessExecutionStatusRelativeTo(target) !== "after";
175
143
  }
176
-
177
144
  function getOuterFunction(path) {
178
- return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path;
145
+ return path.isProgram() ? path : (path.parentPath.scope.getFunctionParent() || path.parentPath.scope.getProgramParent()).path;
179
146
  }
180
-
181
147
  function isExecutionUncertain(type, key) {
182
148
  switch (type) {
183
149
  case "LogicalExpression":
184
150
  return key === "right";
185
-
186
151
  case "ConditionalExpression":
187
152
  case "IfStatement":
188
153
  return key === "consequent" || key === "alternate";
189
-
190
154
  case "WhileStatement":
191
155
  case "DoWhileStatement":
192
156
  case "ForInStatement":
193
157
  case "ForOfStatement":
194
158
  return key === "body";
195
-
196
159
  case "ForStatement":
197
160
  return key === "body" || key === "update";
198
-
199
161
  case "SwitchStatement":
200
162
  return key === "cases";
201
-
202
163
  case "TryStatement":
203
164
  return key === "handler";
204
-
205
165
  case "AssignmentPattern":
206
166
  return key === "right";
207
-
208
167
  case "OptionalMemberExpression":
209
168
  return key === "property";
210
-
211
169
  case "OptionalCallExpression":
212
170
  return key === "arguments";
213
-
214
171
  default:
215
172
  return false;
216
173
  }
217
174
  }
218
-
219
175
  function isExecutionUncertainInList(paths, maxIndex) {
220
176
  for (let i = 0; i < maxIndex; i++) {
221
177
  const path = paths[i];
222
-
223
178
  if (isExecutionUncertain(path.parent.type, path.parentKey)) {
224
179
  return true;
225
180
  }
226
181
  }
227
-
228
182
  return false;
229
183
  }
230
-
184
+ const SYMBOL_CHECKING = Symbol();
231
185
  function _guessExecutionStatusRelativeTo(target) {
186
+ return _guessExecutionStatusRelativeToCached(this, target, new Map());
187
+ }
188
+ function _guessExecutionStatusRelativeToCached(base, target, cache) {
232
189
  const funcParent = {
233
- this: getOuterFunction(this),
190
+ this: getOuterFunction(base),
234
191
  target: getOuterFunction(target)
235
192
  };
236
-
237
193
  if (funcParent.target.node !== funcParent.this.node) {
238
- return this._guessExecutionStatusRelativeToDifferentFunctions(funcParent.target);
194
+ return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);
239
195
  }
240
-
241
196
  const paths = {
242
197
  target: target.getAncestry(),
243
- this: this.getAncestry()
198
+ this: base.getAncestry()
244
199
  };
245
- if (paths.target.indexOf(this) >= 0) return "after";
200
+ if (paths.target.indexOf(base) >= 0) return "after";
246
201
  if (paths.this.indexOf(target) >= 0) return "before";
247
202
  let commonPath;
248
203
  const commonIndex = {
249
204
  target: 0,
250
205
  this: 0
251
206
  };
252
-
253
207
  while (!commonPath && commonIndex.this < paths.this.length) {
254
208
  const path = paths.this[commonIndex.this];
255
209
  commonIndex.target = paths.target.indexOf(path);
256
-
257
210
  if (commonIndex.target >= 0) {
258
211
  commonPath = path;
259
212
  } else {
260
213
  commonIndex.this++;
261
214
  }
262
215
  }
263
-
264
216
  if (!commonPath) {
265
217
  throw new Error("Internal Babel error - The two compared nodes" + " don't appear to belong to the same program.");
266
218
  }
267
-
268
219
  if (isExecutionUncertainInList(paths.this, commonIndex.this - 1) || isExecutionUncertainInList(paths.target, commonIndex.target - 1)) {
269
220
  return "unknown";
270
221
  }
271
-
272
222
  const divergence = {
273
223
  this: paths.this[commonIndex.this - 1],
274
224
  target: paths.target[commonIndex.target - 1]
275
225
  };
276
-
277
226
  if (divergence.target.listKey && divergence.this.listKey && divergence.target.container === divergence.this.container) {
278
227
  return divergence.target.key > divergence.this.key ? "before" : "after";
279
228
  }
280
-
281
229
  const keys = VISITOR_KEYS[commonPath.type];
282
230
  const keyPosition = {
283
231
  this: keys.indexOf(divergence.this.parentKey),
@@ -285,53 +233,57 @@ function _guessExecutionStatusRelativeTo(target) {
285
233
  };
286
234
  return keyPosition.target > keyPosition.this ? "before" : "after";
287
235
  }
288
-
289
- const executionOrderCheckedNodes = new WeakSet();
290
-
291
- function _guessExecutionStatusRelativeToDifferentFunctions(target) {
292
- if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
236
+ function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) {
237
+ if (!target.isFunctionDeclaration()) {
238
+ if (_guessExecutionStatusRelativeToCached(base, target, cache) === "before") {
239
+ return "before";
240
+ }
241
+ return "unknown";
242
+ } else if (target.parentPath.isExportDeclaration()) {
293
243
  return "unknown";
294
244
  }
295
-
296
245
  const binding = target.scope.getBinding(target.node.id.name);
297
246
  if (!binding.references) return "before";
298
247
  const referencePaths = binding.referencePaths;
299
248
  let allStatus;
300
-
301
249
  for (const path of referencePaths) {
302
250
  const childOfFunction = !!path.find(path => path.node === target.node);
303
251
  if (childOfFunction) continue;
304
-
305
252
  if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
306
253
  return "unknown";
307
254
  }
308
-
309
- if (executionOrderCheckedNodes.has(path.node)) continue;
310
- executionOrderCheckedNodes.add(path.node);
311
-
312
- const status = this._guessExecutionStatusRelativeTo(path);
313
-
314
- executionOrderCheckedNodes.delete(path.node);
315
-
255
+ const status = _guessExecutionStatusRelativeToCached(base, path, cache);
316
256
  if (allStatus && allStatus !== status) {
317
257
  return "unknown";
318
258
  } else {
319
259
  allStatus = status;
320
260
  }
321
261
  }
322
-
323
262
  return allStatus;
324
263
  }
325
-
264
+ function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, cache) {
265
+ let nodeMap = cache.get(base.node);
266
+ let cached;
267
+ if (!nodeMap) {
268
+ cache.set(base.node, nodeMap = new Map());
269
+ } else if (cached = nodeMap.get(target.node)) {
270
+ if (cached === SYMBOL_CHECKING) {
271
+ return "unknown";
272
+ }
273
+ return cached;
274
+ }
275
+ nodeMap.set(target.node, SYMBOL_CHECKING);
276
+ const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache);
277
+ nodeMap.set(target.node, result);
278
+ return result;
279
+ }
326
280
  function resolve(dangerous, resolved) {
327
281
  return this._resolve(dangerous, resolved) || this;
328
282
  }
329
-
330
283
  function _resolve(dangerous, resolved) {
331
284
  if (resolved && resolved.indexOf(this) >= 0) return;
332
285
  resolved = resolved || [];
333
286
  resolved.push(this);
334
-
335
287
  if (this.isVariableDeclarator()) {
336
288
  if (this.get("id").isIdentifier()) {
337
289
  return this.get("init").resolve(dangerous, resolved);
@@ -341,7 +293,6 @@ function _resolve(dangerous, resolved) {
341
293
  if (!binding) return;
342
294
  if (!binding.constant) return;
343
295
  if (binding.kind === "module") return;
344
-
345
296
  if (binding.path !== this) {
346
297
  const ret = binding.path.resolve(dangerous, resolved);
347
298
  if (this.find(parent => parent.node === ret.node)) return;
@@ -354,10 +305,8 @@ function _resolve(dangerous, resolved) {
354
305
  if (!isLiteral(targetKey)) return;
355
306
  const targetName = targetKey.value;
356
307
  const target = this.get("object").resolve(dangerous, resolved);
357
-
358
308
  if (target.isObjectExpression()) {
359
309
  const props = target.get("properties");
360
-
361
310
  for (const prop of props) {
362
311
  if (!prop.isProperty()) continue;
363
312
  const key = prop.get("key");
@@ -376,41 +325,35 @@ function _resolve(dangerous, resolved) {
376
325
  }
377
326
  }
378
327
  }
379
-
380
328
  function isConstantExpression() {
381
329
  if (this.isIdentifier()) {
382
330
  const binding = this.scope.getBinding(this.node.name);
383
331
  if (!binding) return false;
384
332
  return binding.constant;
385
333
  }
386
-
387
334
  if (this.isLiteral()) {
388
335
  if (this.isRegExpLiteral()) {
389
336
  return false;
390
337
  }
391
-
392
338
  if (this.isTemplateLiteral()) {
393
339
  return this.get("expressions").every(expression => expression.isConstantExpression());
394
340
  }
395
-
396
341
  return true;
397
342
  }
398
-
399
343
  if (this.isUnaryExpression()) {
400
344
  if (this.node.operator !== "void") {
401
345
  return false;
402
346
  }
403
-
404
347
  return this.get("argument").isConstantExpression();
405
348
  }
406
-
407
349
  if (this.isBinaryExpression()) {
408
- return this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
350
+ const {
351
+ operator
352
+ } = this.node;
353
+ return operator !== "in" && operator !== "instanceof" && this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
409
354
  }
410
-
411
355
  return false;
412
356
  }
413
-
414
357
  function isInStrictMode() {
415
358
  const start = this.isProgram() ? this : this.parentPath;
416
359
  const strictParent = start.find(path => {
@@ -418,14 +361,17 @@ function isInStrictMode() {
418
361
  sourceType: "module"
419
362
  })) return true;
420
363
  if (path.isClass()) return true;
421
- if (!path.isProgram() && !path.isFunction()) return false;
422
-
423
364
  if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
424
365
  return false;
425
366
  }
426
-
427
- const body = path.isFunction() ? path.node.body : path.node;
428
-
367
+ let body;
368
+ if (path.isFunction()) {
369
+ body = path.node.body;
370
+ } else if (path.isProgram()) {
371
+ body = path.node;
372
+ } else {
373
+ return false;
374
+ }
429
375
  for (const directive of body.directives) {
430
376
  if (directive.value.value === "use strict") {
431
377
  return true;
@@ -433,4 +379,6 @@ function isInStrictMode() {
433
379
  }
434
380
  });
435
381
  return !!strictParent;
436
- }
382
+ }
383
+
384
+ //# sourceMappingURL=introspection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_t","require","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","exports","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","SYMBOL_CHECKING","Symbol","_guessExecutionStatusRelativeToCached","Map","base","cache","funcParent","this","_guessExecutionStatusRelativeToDifferentFunctionsCached","getAncestry","indexOf","commonPath","commonIndex","Error","divergence","listKey","keys","keyPosition","_guessExecutionStatusRelativeToDifferentFunctionsInternal","isFunctionDeclaration","isExportDeclaration","id","references","referencePaths","allStatus","childOfFunction","find","isCallExpression","status","nodeMap","cached","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.ts\";\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 as t.Node)\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.isProgram()\n ? path\n : (\n path.parentPath.scope.getFunctionParent() ||\n path.parentPath.scope.getProgramParent()\n ).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\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 SYMBOL_CHECKING = Symbol();\n\ntype ExecutionStatusCache = Map<\n t.Node,\n Map<t.Node, RelativeExecutionStatus | typeof SYMBOL_CHECKING>\n>;\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),\n target: keys.indexOf(divergence.target.parentKey),\n };\n return keyPosition.target > keyPosition.this ? \"before\" : \"after\";\n}\n\nfunction _guessExecutionStatusRelativeToDifferentFunctionsInternal(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n if (!target.isFunctionDeclaration()) {\n if (\n _guessExecutionStatusRelativeToCached(base, target, cache) === \"before\"\n ) {\n return \"before\";\n }\n return \"unknown\";\n } else if (target.parentPath.isExportDeclaration()) {\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 const status = _guessExecutionStatusRelativeToCached(base, path, cache);\n\n if (allStatus && allStatus !== status) {\n return \"unknown\";\n } else {\n allStatus = status;\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 let cached;\n\n if (!nodeMap) {\n cache.set(base.node, (nodeMap = new Map()));\n } else if ((cached = nodeMap.get(target.node))) {\n if (cached === SYMBOL_CHECKING) {\n return \"unknown\";\n }\n return cached;\n }\n\n nodeMap.set(target.node, SYMBOL_CHECKING);\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,IAAAA,EAAA,GAAAC,OAAA;AAUsB;EATpBC,uBAAuB;EACvBC,YAAY;EACZC,gBAAgB;EAChBC,YAAY;EACZC,YAAY;EACZC,SAAS;EACTC,eAAe;EACfC,MAAM;EACNC,cAAc,EAAIC;AAAe,IAAAX,EAAA;AAW5B,SAASU,cAAcA,CAE5BE,OAAe,EACfC,YAAsB,EACb;EACT,OAAOF,eAAe,CAAC,IAAI,CAACG,IAAI,EAAEF,OAAO,EAAEC,YAAY,CAAC;AAC1D;AAOO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