@babel/traverse 8.0.0-alpha.11 → 8.0.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,13 +1,10 @@
1
- import * as _t from '@babel/types';
2
1
  import buildDebug from 'debug';
3
- import splitExportDeclaration from '@babel/helper-split-export-declaration';
4
- import environmentVisitor, { requeueComputedKeyAndDecorators } from '@babel/helper-environment-visitor';
5
- import globals from 'globals';
6
- import generator from '@babel/generator';
7
2
  import { codeFrameColumns } from '@babel/code-frame';
3
+ import * as _t from '@babel/types';
8
4
  import { parse } from '@babel/parser';
9
- import hoistVariables from '@babel/helper-hoist-variables';
10
- import nameFunction from '@babel/helper-function-name';
5
+ import globals from 'globals';
6
+ import generator from '@babel/generator';
7
+ import template from '@babel/template';
11
8
 
12
9
  const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
13
10
  const ReferencedMemberExpression = ["MemberExpression"];
@@ -70,12 +67,12 @@ const {
70
67
  isStatement: nodeIsStatement,
71
68
  isVar: nodeIsVar,
72
69
  isVariableDeclaration: isVariableDeclaration$2,
73
- react: react$1,
70
+ react,
74
71
  isForOfStatement
75
72
  } = _t;
76
73
  const {
77
74
  isCompatTag
78
- } = react$1;
75
+ } = react;
79
76
  function isReferencedIdentifier(opts) {
80
77
  const {
81
78
  node,
@@ -291,8 +288,8 @@ function verify$1(visitor) {
291
288
  validateVisitorMethods(nodeType, visitor[nodeType]);
292
289
  }
293
290
  if (shouldIgnoreKey(nodeType)) continue;
294
- if (TYPES.indexOf(nodeType) < 0) {
295
- throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
291
+ if (!TYPES.includes(nodeType)) {
292
+ throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"8.0.0-alpha.13"}`);
296
293
  }
297
294
  const visitors = visitor[nodeType];
298
295
  if (typeof visitors === "object") {
@@ -316,7 +313,10 @@ function validateVisitorMethods(path, val) {
316
313
  }
317
314
  }
318
315
  function merge(visitors, states = [], wrapper) {
319
- const mergedVisitor = {};
316
+ const mergedVisitor = {
317
+ _verified: true,
318
+ _exploded: true
319
+ };
320
320
  for (let i = 0; i < visitors.length; i++) {
321
321
  const visitor = explode$1(visitors[i]);
322
322
  const state = states[i];
@@ -335,12 +335,7 @@ function merge(visitors, states = [], wrapper) {
335
335
  mergePair(nodeVisitor, typeVisitor);
336
336
  }
337
337
  }
338
- {
339
- return Object.assign({}, mergedVisitor, {
340
- _exploded: true,
341
- _verified: true
342
- });
343
- }
338
+ return mergedVisitor;
344
339
  }
345
340
  function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
346
341
  const newVisitor = {};
@@ -406,50 +401,40 @@ function mergePair(dest, src) {
406
401
  dest[phase] = [].concat(dest[phase] || [], src[phase]);
407
402
  }
408
403
  }
404
+ const _environmentVisitor = {
405
+ FunctionParent(path) {
406
+ if (path.isArrowFunctionExpression()) return;
407
+ path.skip();
408
+ if (path.isMethod()) {
409
+ {
410
+ path.requeueComputedKeyAndDecorators();
411
+ }
412
+ }
413
+ },
414
+ Property(path) {
415
+ if (path.isObjectProperty()) return;
416
+ path.skip();
417
+ {
418
+ path.requeueComputedKeyAndDecorators();
419
+ }
420
+ }
421
+ };
422
+ function environmentVisitor(visitor) {
423
+ return merge([_environmentVisitor, visitor]);
424
+ }
409
425
 
410
426
  var visitors = /*#__PURE__*/Object.freeze({
411
427
  __proto__: null,
428
+ environmentVisitor: environmentVisitor,
412
429
  explode: explode$1,
413
430
  isExplodedVisitor: isExplodedVisitor,
414
431
  merge: merge,
415
432
  verify: verify$1
416
433
  });
417
434
 
418
- let pathsCache = new WeakMap();
419
- let scope = new WeakMap();
420
- function clear() {
421
- clearPath();
422
- clearScope();
423
- }
424
- function clearPath() {
425
- pathsCache = new WeakMap();
426
- }
427
- function clearScope() {
428
- scope = new WeakMap();
429
- }
430
- const nullHub = Object.freeze({});
431
- function getCachedPaths(hub, parent) {
432
- return pathsCache.get(hub ?? nullHub)?.get(parent);
433
- }
434
- function getOrCreateCachedPaths(hub, parent) {
435
- let parents = pathsCache.get(hub ?? nullHub);
436
- if (!parents) pathsCache.set(hub ?? nullHub, parents = new WeakMap());
437
- let paths = parents.get(parent);
438
- if (!paths) parents.set(parent, paths = new Map());
439
- return paths;
440
- }
441
-
442
- var cache = /*#__PURE__*/Object.freeze({
443
- __proto__: null,
444
- clear: clear,
445
- clearPath: clearPath,
446
- clearScope: clearScope,
447
- getCachedPaths: getCachedPaths,
448
- getOrCreateCachedPaths: getOrCreateCachedPaths,
449
- get path () { return pathsCache; },
450
- get scope () { return scope; }
451
- });
452
-
435
+ const {
436
+ getAssignmentIdentifiers: getAssignmentIdentifiers$1
437
+ } = _t;
453
438
  const renameVisitor = {
454
439
  ReferencedIdentifier({
455
440
  node
@@ -462,7 +447,9 @@ const renameVisitor = {
462
447
  if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
463
448
  path.skip();
464
449
  if (path.isMethod()) {
465
- requeueComputedKeyAndDecorators(path);
450
+ {
451
+ path.requeueComputedKeyAndDecorators();
452
+ }
466
453
  }
467
454
  }
468
455
  },
@@ -479,7 +466,7 @@ const renameVisitor = {
479
466
  },
480
467
  "AssignmentExpression|Declaration|VariableDeclarator"(path, state) {
481
468
  if (path.isVariableDeclaration()) return;
482
- const ids = path.getOuterBindingIdentifiers();
469
+ const ids = path.isAssignmentExpression() ? getAssignmentIdentifiers$1(path.node) : path.getOuterBindingIdentifiers();
483
470
  for (const name in ids) {
484
471
  if (name === state.oldName) ids[name].name = state.newName;
485
472
  }
@@ -507,7 +494,7 @@ class Renamer {
507
494
  if (maybeExportDeclar.isExportAllDeclaration()) {
508
495
  return;
509
496
  }
510
- splitExportDeclaration(maybeExportDeclar);
497
+ maybeExportDeclar.splitExportDeclaration();
511
498
  }
512
499
  maybeConvertFromClassFunctionDeclaration(path) {
513
500
  return path;
@@ -533,9 +520,18 @@ class Renamer {
533
520
  }
534
521
  }
535
522
  const blockToTraverse = scope.block;
536
- traverseNode(blockToTraverse, explode$1(renameVisitor), scope, this, scope.path, {
523
+ const skipKeys = {
537
524
  discriminant: true
538
- });
525
+ };
526
+ if (_t.isMethod(blockToTraverse)) {
527
+ if (blockToTraverse.computed) {
528
+ skipKeys.key = true;
529
+ }
530
+ if (!_t.isObjectMethod(blockToTraverse)) {
531
+ skipKeys.decorators = true;
532
+ }
533
+ }
534
+ traverseNode(blockToTraverse, explode$1(renameVisitor), scope, this, scope.path, skipKeys);
539
535
  {
540
536
  scope.removeOwnBinding(oldName);
541
537
  scope.bindings[newName] = binding;
@@ -589,13 +585,13 @@ class Binding {
589
585
  }
590
586
  reassign(path) {
591
587
  this.constant = false;
592
- if (this.constantViolations.indexOf(path) !== -1) {
588
+ if (this.constantViolations.includes(path)) {
593
589
  return;
594
590
  }
595
591
  this.constantViolations.push(path);
596
592
  }
597
593
  reference(path) {
598
- if (this.referencePaths.indexOf(path) !== -1) {
594
+ if (this.referencePaths.includes(path)) {
599
595
  return;
600
596
  }
601
597
  this.referenced = true;
@@ -623,8 +619,44 @@ function isDeclaredInLoop(path) {
623
619
  return false;
624
620
  }
625
621
 
622
+ let pathsCache = new WeakMap();
623
+ let scope = new WeakMap();
624
+ function clear() {
625
+ clearPath();
626
+ clearScope();
627
+ }
628
+ function clearPath() {
629
+ pathsCache = new WeakMap();
630
+ }
631
+ function clearScope() {
632
+ scope = new WeakMap();
633
+ }
634
+ const nullHub = Object.freeze({});
635
+ function getCachedPaths(hub, parent) {
636
+ return pathsCache.get(hub ?? nullHub)?.get(parent);
637
+ }
638
+ function getOrCreateCachedPaths(hub, parent) {
639
+ let parents = pathsCache.get(hub ?? nullHub);
640
+ if (!parents) pathsCache.set(hub ?? nullHub, parents = new WeakMap());
641
+ let paths = parents.get(parent);
642
+ if (!paths) parents.set(parent, paths = new Map());
643
+ return paths;
644
+ }
645
+
646
+ var cache = /*#__PURE__*/Object.freeze({
647
+ __proto__: null,
648
+ clear: clear,
649
+ clearPath: clearPath,
650
+ clearScope: clearScope,
651
+ getCachedPaths: getCachedPaths,
652
+ getOrCreateCachedPaths: getOrCreateCachedPaths,
653
+ get path () { return pathsCache; },
654
+ get scope () { return scope; }
655
+ });
656
+
626
657
  const {
627
658
  NOT_LOCAL_BINDING,
659
+ assignmentExpression: assignmentExpression$3,
628
660
  callExpression: callExpression$3,
629
661
  cloneNode: cloneNode$3,
630
662
  getBindingIdentifiers: getBindingIdentifiers$3,
@@ -656,6 +688,7 @@ const {
656
688
  isThisExpression,
657
689
  isUnaryExpression,
658
690
  isVariableDeclaration: isVariableDeclaration$1,
691
+ expressionStatement: expressionStatement$3,
659
692
  matchesPattern: matchesPattern$1,
660
693
  memberExpression: memberExpression$1,
661
694
  numericLiteral: numericLiteral$2,
@@ -669,7 +702,8 @@ const {
669
702
  isMetaProperty,
670
703
  isPrivateName,
671
704
  isExportDeclaration,
672
- buildUndefinedNode: buildUndefinedNode$1
705
+ buildUndefinedNode: buildUndefinedNode$1,
706
+ sequenceExpression: sequenceExpression$2
673
707
  } = _t;
674
708
  function gatherNodeParts(node, parts) {
675
709
  switch (node?.type) {
@@ -878,12 +912,12 @@ const collectorVisitor = {
878
912
  for (const param of params) {
879
913
  path.scope.registerBinding("param", param);
880
914
  }
881
- if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
915
+ if (path.isFunctionExpression() && path.node.id && !path.node.id[NOT_LOCAL_BINDING]) {
882
916
  path.scope.registerBinding("local", path.get("id"), path);
883
917
  }
884
918
  },
885
919
  ClassExpression(path) {
886
- if (path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
920
+ if (path.node.id && !path.node.id[NOT_LOCAL_BINDING]) {
887
921
  path.scope.registerBinding("local", path.get("id"), path);
888
922
  }
889
923
  },
@@ -896,8 +930,8 @@ class Scope {
896
930
  uid;
897
931
  path;
898
932
  block;
899
- labels;
900
933
  inited;
934
+ labels;
901
935
  bindings;
902
936
  references;
903
937
  globals;
@@ -932,15 +966,6 @@ class Scope {
932
966
  } while (path && !parent);
933
967
  return parent?.scope;
934
968
  }
935
- get parentBlock() {
936
- return this.path.parent;
937
- }
938
- get hub() {
939
- return this.path.hub;
940
- }
941
- traverse(node, opts, state) {
942
- traverse(node, opts, this, state, this.path);
943
- }
944
969
  generateDeclaredUidIdentifier(name) {
945
970
  const id = this.generateUidIdentifier(name);
946
971
  this.push({
@@ -952,11 +977,12 @@ class Scope {
952
977
  return identifier$3(this.generateUid(name));
953
978
  }
954
979
  generateUid(name = "temp") {
955
- name = toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
980
+ name = toIdentifier(name).replace(/^_+/, "").replace(/\d+$/g, "");
956
981
  let uid;
957
982
  let i = 1;
958
983
  do {
959
- uid = this._generateUid(name, i);
984
+ uid = `_${name}`;
985
+ if (i > 1) uid += i;
960
986
  i++;
961
987
  } while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
962
988
  const program = this.getProgramParent();
@@ -964,11 +990,6 @@ class Scope {
964
990
  program.uids[uid] = true;
965
991
  return uid;
966
992
  }
967
- _generateUid(name, i) {
968
- let id = name;
969
- if (i > 1) id += i;
970
- return `_${id}`;
971
- }
972
993
  generateUidBasedOnNode(node, defaultName) {
973
994
  const parts = [];
974
995
  gatherNodeParts(node, parts);
@@ -1012,7 +1033,7 @@ class Scope {
1012
1033
  if (local.kind === "local") return;
1013
1034
  const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const";
1014
1035
  if (duplicate) {
1015
- throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
1036
+ throw this.path.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
1016
1037
  }
1017
1038
  }
1018
1039
  rename(oldName, newName) {
@@ -1025,12 +1046,6 @@ class Scope {
1025
1046
  }
1026
1047
  }
1027
1048
  }
1028
- _renameFromMap(map, oldName, newName, value) {
1029
- if (map[oldName]) {
1030
- map[newName] = value;
1031
- map[oldName] = null;
1032
- }
1033
- }
1034
1049
  dump() {
1035
1050
  const sep = "-".repeat(60);
1036
1051
  console.log(sep);
@@ -1049,37 +1064,6 @@ class Scope {
1049
1064
  } while (scope = scope.parent);
1050
1065
  console.log(sep);
1051
1066
  }
1052
- toArray(node, i, arrayLikeIsIterable) {
1053
- if (isIdentifier$5(node)) {
1054
- const binding = this.getBinding(node.name);
1055
- if (binding?.constant && binding.path.isGenericType("Array")) {
1056
- return node;
1057
- }
1058
- }
1059
- if (isArrayExpression(node)) {
1060
- return node;
1061
- }
1062
- if (isIdentifier$5(node, {
1063
- name: "arguments"
1064
- })) {
1065
- return callExpression$3(memberExpression$1(memberExpression$1(memberExpression$1(identifier$3("Array"), identifier$3("prototype")), identifier$3("slice")), identifier$3("call")), [node]);
1066
- }
1067
- let helperName;
1068
- const args = [node];
1069
- if (i === true) {
1070
- helperName = "toConsumableArray";
1071
- } else if (typeof i === "number") {
1072
- args.push(numericLiteral$2(i));
1073
- helperName = "slicedToArray";
1074
- } else {
1075
- helperName = "toArray";
1076
- }
1077
- if (arrayLikeIsIterable) {
1078
- args.unshift(this.hub.addHelper(helperName));
1079
- helperName = "maybeArrayLike";
1080
- }
1081
- return callExpression$3(this.hub.addHelper(helperName), args);
1082
- }
1083
1067
  hasLabel(name) {
1084
1068
  return !!this.getLabel(name);
1085
1069
  }
@@ -1125,7 +1109,7 @@ class Scope {
1125
1109
  return buildUndefinedNode$1();
1126
1110
  }
1127
1111
  registerConstantViolation(path) {
1128
- const ids = path.getBindingIdentifiers();
1112
+ const ids = path.getAssignmentIdentifiers();
1129
1113
  for (const name of Object.keys(ids)) {
1130
1114
  this.getBinding(name)?.reassign(path);
1131
1115
  }
@@ -1307,7 +1291,7 @@ class Scope {
1307
1291
  path.traverse(collectorVisitor, state);
1308
1292
  this.crawling = false;
1309
1293
  for (const path of state.assignments) {
1310
- const ids = path.getBindingIdentifiers();
1294
+ const ids = path.getAssignmentIdentifiers();
1311
1295
  for (const name of Object.keys(ids)) {
1312
1296
  if (path.scope.getBinding(name)) continue;
1313
1297
  programParent.addGlobal(ids[name]);
@@ -1415,20 +1399,6 @@ class Scope {
1415
1399
  } while (scope);
1416
1400
  return ids;
1417
1401
  }
1418
- getAllBindingsOfKind(...kinds) {
1419
- const ids = Object.create(null);
1420
- for (const kind of kinds) {
1421
- let scope = this;
1422
- do {
1423
- for (const name of Object.keys(scope.bindings)) {
1424
- const binding = scope.bindings[name];
1425
- if (binding.kind === kind) ids[name] = binding;
1426
- }
1427
- scope = scope.parent;
1428
- } while (scope);
1429
- }
1430
- return ids;
1431
- }
1432
1402
  bindingIdentifierEquals(name, node) {
1433
1403
  return this.getBindingIdentifier(name) === node;
1434
1404
  }
@@ -1462,16 +1432,23 @@ class Scope {
1462
1432
  }
1463
1433
  hasBinding(name, opts) {
1464
1434
  if (!name) return false;
1465
- if (this.hasOwnBinding(name)) return true;
1466
- {
1467
- if (typeof opts === "boolean") opts = {
1468
- noGlobals: opts
1469
- };
1470
- }
1471
- if (this.parentHasBinding(name, opts)) return true;
1472
- if (!opts?.noUids && this.hasUid(name)) return true;
1473
- if (!opts?.noGlobals && Scope.globals.includes(name)) return true;
1474
- if (!opts?.noGlobals && Scope.contextVariables.includes(name)) return true;
1435
+ let scope = this;
1436
+ do {
1437
+ if (scope.hasOwnBinding(name)) {
1438
+ return true;
1439
+ }
1440
+ } while (scope = scope.parent);
1441
+ let noGlobals;
1442
+ let noUids;
1443
+ if (typeof opts === "object") {
1444
+ noGlobals = opts.noGlobals;
1445
+ noUids = opts.noUids;
1446
+ } else if (typeof opts === "boolean") {
1447
+ noGlobals = opts;
1448
+ }
1449
+ if (!noUids && this.hasUid(name)) return true;
1450
+ if (!noGlobals && Scope.globals.includes(name)) return true;
1451
+ if (!noGlobals && Scope.contextVariables.includes(name)) return true;
1475
1452
  return false;
1476
1453
  }
1477
1454
  parentHasBinding(name, opts) {
@@ -1497,6 +1474,54 @@ class Scope {
1497
1474
  }
1498
1475
  } while (scope = scope.parent);
1499
1476
  }
1477
+ hoistVariables(emit = id => this.push({
1478
+ id
1479
+ })) {
1480
+ this.crawl();
1481
+ const seen = new Set();
1482
+ for (const name of Object.keys(this.bindings)) {
1483
+ const binding = this.bindings[name];
1484
+ if (!binding) continue;
1485
+ const {
1486
+ path
1487
+ } = binding;
1488
+ if (!path.isVariableDeclarator()) continue;
1489
+ const {
1490
+ parent,
1491
+ parentPath
1492
+ } = path;
1493
+ if (parent.kind !== "var" || seen.has(parent)) continue;
1494
+ seen.add(path.parent);
1495
+ let firstId;
1496
+ const init = [];
1497
+ for (const decl of parent.declarations) {
1498
+ firstId ??= decl.id;
1499
+ if (decl.init) {
1500
+ init.push(assignmentExpression$3("=", decl.id, decl.init));
1501
+ }
1502
+ const ids = Object.keys(getBindingIdentifiers$3(decl, false, true, true));
1503
+ for (const name of ids) {
1504
+ emit(identifier$3(name), decl.init != null);
1505
+ }
1506
+ }
1507
+ if (parentPath.parentPath.isFor({
1508
+ left: parent
1509
+ })) {
1510
+ parentPath.replaceWith(firstId);
1511
+ } else if (init.length === 0) {
1512
+ parentPath.remove();
1513
+ } else {
1514
+ const expr = init.length === 1 ? init[0] : sequenceExpression$2(init);
1515
+ if (parentPath.parentPath.isForStatement({
1516
+ init: parent
1517
+ })) {
1518
+ parentPath.replaceWith(expr);
1519
+ } else {
1520
+ parentPath.replaceWith(expressionStatement$3(expr));
1521
+ }
1522
+ }
1523
+ }
1524
+ }
1500
1525
  }
1501
1526
 
1502
1527
  const {
@@ -1670,7 +1695,7 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
1670
1695
  const testType = getConditionalAnnotation(binding, path, name);
1671
1696
  if (testType) {
1672
1697
  const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
1673
- constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0);
1698
+ constantViolations = constantViolations.filter(path => !testConstantViolations.includes(path));
1674
1699
  types.push(testType.typeAnnotation);
1675
1700
  }
1676
1701
  if (constantViolations.length) {
@@ -1712,7 +1737,7 @@ function inferAnnotationFromBinaryExpression(name, path) {
1712
1737
  if (operator === "===") {
1713
1738
  return target.getTypeAnnotation();
1714
1739
  }
1715
- if (BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
1740
+ if (BOOLEAN_NUMBER_BINARY_OPERATORS.includes(operator)) {
1716
1741
  return numberTypeAnnotation$1();
1717
1742
  }
1718
1743
  return;
@@ -1830,19 +1855,19 @@ function UnaryExpression(node) {
1830
1855
  const operator = node.operator;
1831
1856
  if (operator === "void") {
1832
1857
  return voidTypeAnnotation$1();
1833
- } else if (NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
1858
+ } else if (NUMBER_UNARY_OPERATORS.includes(operator)) {
1834
1859
  return numberTypeAnnotation();
1835
- } else if (STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
1860
+ } else if (STRING_UNARY_OPERATORS.includes(operator)) {
1836
1861
  return stringTypeAnnotation$1();
1837
- } else if (BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
1862
+ } else if (BOOLEAN_UNARY_OPERATORS.includes(operator)) {
1838
1863
  return booleanTypeAnnotation();
1839
1864
  }
1840
1865
  }
1841
1866
  function BinaryExpression(node) {
1842
1867
  const operator = node.operator;
1843
- if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
1868
+ if (NUMBER_BINARY_OPERATORS.includes(operator)) {
1844
1869
  return numberTypeAnnotation();
1845
- } else if (BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
1870
+ } else if (BOOLEAN_BINARY_OPERATORS.includes(operator)) {
1846
1871
  return booleanTypeAnnotation();
1847
1872
  } else if (operator === "+") {
1848
1873
  const right = this.get("right");
@@ -2011,7 +2036,7 @@ function getTypeAnnotation() {
2011
2036
  if (type != null) {
2012
2037
  return type;
2013
2038
  }
2014
- type = this._getTypeAnnotation() || anyTypeAnnotation();
2039
+ type = _getTypeAnnotation.call(this) || anyTypeAnnotation();
2015
2040
  if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {
2016
2041
  type = type.typeAnnotation;
2017
2042
  }
@@ -2118,53 +2143,333 @@ function isGenericType(genericName) {
2118
2143
  });
2119
2144
  }
2120
2145
 
2146
+ const hooks = [function (self, parent) {
2147
+ const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
2148
+ if (removeParent) {
2149
+ parent.remove();
2150
+ return true;
2151
+ }
2152
+ }, function (self, parent) {
2153
+ if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
2154
+ parent.replaceWith(parent.node.expressions[0]);
2155
+ return true;
2156
+ }
2157
+ }, function (self, parent) {
2158
+ if (parent.isBinary()) {
2159
+ if (self.key === "left") {
2160
+ parent.replaceWith(parent.node.right);
2161
+ } else {
2162
+ parent.replaceWith(parent.node.left);
2163
+ }
2164
+ return true;
2165
+ }
2166
+ }, function (self, parent) {
2167
+ if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
2168
+ self.replaceWith({
2169
+ type: "BlockStatement",
2170
+ body: []
2171
+ });
2172
+ return true;
2173
+ }
2174
+ }];
2175
+
2176
+ const {
2177
+ getBindingIdentifiers: getBindingIdentifiers$2
2178
+ } = _t;
2179
+ function remove() {
2180
+ _assertUnremoved.call(this);
2181
+ resync.call(this);
2182
+ if (_callRemovalHooks.call(this)) {
2183
+ _markRemoved.call(this);
2184
+ return;
2185
+ }
2186
+ if (!this.opts?.noScope) {
2187
+ _removeFromScope.call(this);
2188
+ }
2189
+ this.shareCommentsWithSiblings();
2190
+ _remove.call(this);
2191
+ _markRemoved.call(this);
2192
+ }
2193
+ function _removeFromScope() {
2194
+ const bindings = getBindingIdentifiers$2(this.node, false, false, true);
2195
+ Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
2196
+ }
2197
+ function _callRemovalHooks() {
2198
+ if (this.parentPath) {
2199
+ for (const fn of hooks) {
2200
+ if (fn(this, this.parentPath)) return true;
2201
+ }
2202
+ }
2203
+ }
2204
+ function _remove() {
2205
+ if (Array.isArray(this.container)) {
2206
+ this.container.splice(this.key, 1);
2207
+ updateSiblingKeys.call(this, this.key, -1);
2208
+ } else {
2209
+ _replaceWith.call(this, null);
2210
+ }
2211
+ }
2212
+ function _markRemoved() {
2213
+ this._traverseFlags |= SHOULD_SKIP | REMOVED;
2214
+ if (this.parent) {
2215
+ getCachedPaths(this.hub, this.parent).delete(this.node);
2216
+ }
2217
+ this.node = null;
2218
+ }
2219
+ function _assertUnremoved() {
2220
+ if (this.removed) {
2221
+ throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
2222
+ }
2223
+ }
2224
+
2121
2225
  const {
2122
- FUNCTION_TYPES,
2123
2226
  arrowFunctionExpression: arrowFunctionExpression$2,
2227
+ assertExpression,
2124
2228
  assignmentExpression: assignmentExpression$2,
2125
- awaitExpression,
2126
2229
  blockStatement: blockStatement$2,
2127
- buildUndefinedNode,
2128
2230
  callExpression: callExpression$2,
2129
2231
  cloneNode: cloneNode$2,
2130
- conditionalExpression: conditionalExpression$1,
2131
2232
  expressionStatement: expressionStatement$2,
2132
- getBindingIdentifiers: getBindingIdentifiers$2,
2133
- identifier: identifier$1,
2134
- inheritLeadingComments,
2135
- inheritTrailingComments,
2136
- inheritsComments,
2137
- isBlockStatement: isBlockStatement$1,
2138
- isEmptyStatement,
2233
+ isAssignmentExpression,
2234
+ isCallExpression,
2235
+ isExportNamedDeclaration,
2139
2236
  isExpression: isExpression$2,
2140
- isExpressionStatement,
2141
- isIfStatement,
2142
- isProgram,
2143
- isStatement,
2144
- isVariableDeclaration,
2145
- removeComments,
2146
- returnStatement: returnStatement$1,
2147
- sequenceExpression: sequenceExpression$1,
2148
- validate: validate$1,
2149
- yieldExpression
2237
+ isIdentifier: isIdentifier$2,
2238
+ isSequenceExpression,
2239
+ isSuper,
2240
+ thisExpression: thisExpression$1
2150
2241
  } = _t;
2151
- function replaceWithMultiple(nodes) {
2152
- this.resync();
2153
- nodes = this._verifyNodeList(nodes);
2154
- inheritLeadingComments(nodes[0], this.node);
2155
- inheritTrailingComments(nodes[nodes.length - 1], this.node);
2156
- getCachedPaths(this.hub, this.parent)?.delete(this.node);
2157
- this.node = this.container[this.key] = null;
2158
- const paths = this.insertAfter(nodes);
2159
- if (this.node) {
2160
- this.requeue();
2161
- } else {
2162
- this.remove();
2163
- }
2164
- return paths;
2165
- }
2166
- function replaceWithSourceString(replacement) {
2167
- this.resync();
2242
+ function insertBefore(nodes_) {
2243
+ _assertUnremoved.call(this);
2244
+ const nodes = _verifyNodeList.call(this, nodes_);
2245
+ const {
2246
+ parentPath,
2247
+ parent
2248
+ } = this;
2249
+ if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
2250
+ return parentPath.insertBefore(nodes);
2251
+ } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
2252
+ if (this.node) nodes.push(this.node);
2253
+ return this.replaceExpressionWithStatements(nodes);
2254
+ } else if (Array.isArray(this.container)) {
2255
+ return _containerInsertBefore.call(this, nodes);
2256
+ } else if (this.isStatementOrBlock()) {
2257
+ const node = this.node;
2258
+ const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
2259
+ this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
2260
+ return this.unshiftContainer("body", nodes);
2261
+ } else {
2262
+ throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
2263
+ }
2264
+ }
2265
+ function _containerInsert(from, nodes) {
2266
+ updateSiblingKeys.call(this, from, nodes.length);
2267
+ const paths = [];
2268
+ this.container.splice(from, 0, ...nodes);
2269
+ for (let i = 0; i < nodes.length; i++) {
2270
+ const to = from + i;
2271
+ const path = this.getSibling(to);
2272
+ paths.push(path);
2273
+ if (this.context?.queue) {
2274
+ pushContext.call(path, this.context);
2275
+ }
2276
+ }
2277
+ const contexts = _getQueueContexts.call(this);
2278
+ for (const path of paths) {
2279
+ setScope.call(path);
2280
+ path.debug("Inserted.");
2281
+ for (const context of contexts) {
2282
+ context.maybeQueue(path, true);
2283
+ }
2284
+ }
2285
+ return paths;
2286
+ }
2287
+ function _containerInsertBefore(nodes) {
2288
+ return _containerInsert.call(this, this.key, nodes);
2289
+ }
2290
+ function _containerInsertAfter(nodes) {
2291
+ return _containerInsert.call(this, this.key + 1, nodes);
2292
+ }
2293
+ const last = arr => arr[arr.length - 1];
2294
+ function isHiddenInSequenceExpression(path) {
2295
+ return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
2296
+ }
2297
+ function isAlmostConstantAssignment(node, scope) {
2298
+ if (!isAssignmentExpression(node) || !isIdentifier$2(node.left)) {
2299
+ return false;
2300
+ }
2301
+ const blockScope = scope.getBlockParent();
2302
+ return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
2303
+ }
2304
+ function insertAfter(nodes_) {
2305
+ _assertUnremoved.call(this);
2306
+ if (this.isSequenceExpression()) {
2307
+ return last(this.get("expressions")).insertAfter(nodes_);
2308
+ }
2309
+ const nodes = _verifyNodeList.call(this, nodes_);
2310
+ const {
2311
+ parentPath,
2312
+ parent
2313
+ } = this;
2314
+ if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
2315
+ return parentPath.insertAfter(nodes.map(node => {
2316
+ return isExpression$2(node) ? expressionStatement$2(node) : node;
2317
+ }));
2318
+ } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
2319
+ const self = this;
2320
+ if (self.node) {
2321
+ const node = self.node;
2322
+ let {
2323
+ scope
2324
+ } = this;
2325
+ if (scope.path.isPattern()) {
2326
+ assertExpression(node);
2327
+ self.replaceWith(callExpression$2(arrowFunctionExpression$2([], node), []));
2328
+ self.get("callee.body").insertAfter(nodes);
2329
+ return [self];
2330
+ }
2331
+ if (isHiddenInSequenceExpression(self)) {
2332
+ nodes.unshift(node);
2333
+ } else if (isCallExpression(node) && isSuper(node.callee)) {
2334
+ nodes.unshift(node);
2335
+ nodes.push(thisExpression$1());
2336
+ } else if (isAlmostConstantAssignment(node, scope)) {
2337
+ nodes.unshift(node);
2338
+ nodes.push(cloneNode$2(node.left));
2339
+ } else if (scope.isPure(node, true)) {
2340
+ nodes.push(node);
2341
+ } else {
2342
+ if (parentPath.isMethod({
2343
+ computed: true,
2344
+ key: node
2345
+ })) {
2346
+ scope = scope.parent;
2347
+ }
2348
+ const temp = scope.generateDeclaredUidIdentifier();
2349
+ nodes.unshift(expressionStatement$2(assignmentExpression$2("=", cloneNode$2(temp), node)));
2350
+ nodes.push(expressionStatement$2(cloneNode$2(temp)));
2351
+ }
2352
+ }
2353
+ return this.replaceExpressionWithStatements(nodes);
2354
+ } else if (Array.isArray(this.container)) {
2355
+ return _containerInsertAfter.call(this, nodes);
2356
+ } else if (this.isStatementOrBlock()) {
2357
+ const node = this.node;
2358
+ const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
2359
+ this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
2360
+ return this.pushContainer("body", nodes);
2361
+ } else {
2362
+ throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
2363
+ }
2364
+ }
2365
+ function updateSiblingKeys(fromIndex, incrementBy) {
2366
+ if (!this.parent) return;
2367
+ const paths = getCachedPaths(this.hub, this.parent) || [];
2368
+ for (const [, path] of paths) {
2369
+ if (typeof path.key === "number" && path.container === this.container && path.key >= fromIndex) {
2370
+ path.key += incrementBy;
2371
+ }
2372
+ }
2373
+ }
2374
+ function _verifyNodeList(nodes) {
2375
+ if (!nodes) {
2376
+ return [];
2377
+ }
2378
+ if (!Array.isArray(nodes)) {
2379
+ nodes = [nodes];
2380
+ }
2381
+ for (let i = 0; i < nodes.length; i++) {
2382
+ const node = nodes[i];
2383
+ let msg;
2384
+ if (!node) {
2385
+ msg = "has falsy node";
2386
+ } else if (typeof node !== "object") {
2387
+ msg = "contains a non-object node";
2388
+ } else if (!node.type) {
2389
+ msg = "without a type";
2390
+ } else if (node instanceof NodePath_Final) {
2391
+ msg = "has a NodePath when it expected a raw object";
2392
+ }
2393
+ if (msg) {
2394
+ const type = Array.isArray(node) ? "array" : typeof node;
2395
+ throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
2396
+ }
2397
+ }
2398
+ return nodes;
2399
+ }
2400
+ function unshiftContainer(listKey, nodes) {
2401
+ _assertUnremoved.call(this);
2402
+ nodes = _verifyNodeList.call(this, nodes);
2403
+ const path = NodePath_Final.get({
2404
+ parentPath: this,
2405
+ parent: this.node,
2406
+ container: this.node[listKey],
2407
+ listKey,
2408
+ key: 0
2409
+ }).setContext(this.context);
2410
+ return _containerInsertBefore.call(path, nodes);
2411
+ }
2412
+ function pushContainer(listKey, nodes) {
2413
+ _assertUnremoved.call(this);
2414
+ const verifiedNodes = _verifyNodeList.call(this, nodes);
2415
+ const container = this.node[listKey];
2416
+ const path = NodePath_Final.get({
2417
+ parentPath: this,
2418
+ parent: this.node,
2419
+ container: container,
2420
+ listKey,
2421
+ key: container.length
2422
+ }).setContext(this.context);
2423
+ return path.replaceWithMultiple(verifiedNodes);
2424
+ }
2425
+
2426
+ const {
2427
+ FUNCTION_TYPES,
2428
+ arrowFunctionExpression: arrowFunctionExpression$1,
2429
+ assignmentExpression: assignmentExpression$1,
2430
+ awaitExpression,
2431
+ blockStatement: blockStatement$1,
2432
+ buildUndefinedNode,
2433
+ callExpression: callExpression$1,
2434
+ cloneNode: cloneNode$1,
2435
+ conditionalExpression: conditionalExpression$1,
2436
+ expressionStatement: expressionStatement$1,
2437
+ getBindingIdentifiers: getBindingIdentifiers$1,
2438
+ identifier: identifier$1,
2439
+ inheritLeadingComments,
2440
+ inheritTrailingComments,
2441
+ inheritsComments,
2442
+ isBlockStatement: isBlockStatement$1,
2443
+ isEmptyStatement,
2444
+ isExpression: isExpression$1,
2445
+ isExpressionStatement,
2446
+ isIfStatement,
2447
+ isProgram,
2448
+ isStatement,
2449
+ isVariableDeclaration,
2450
+ removeComments,
2451
+ returnStatement: returnStatement$1,
2452
+ sequenceExpression: sequenceExpression$1,
2453
+ validate: validate$1,
2454
+ yieldExpression
2455
+ } = _t;
2456
+ function replaceWithMultiple(nodes) {
2457
+ resync.call(this);
2458
+ nodes = _verifyNodeList.call(this, nodes);
2459
+ inheritLeadingComments(nodes[0], this.node);
2460
+ inheritTrailingComments(nodes[nodes.length - 1], this.node);
2461
+ getCachedPaths(this.hub, this.parent)?.delete(this.node);
2462
+ this.node = this.container[this.key] = null;
2463
+ const paths = this.insertAfter(nodes);
2464
+ if (this.node) {
2465
+ this.requeue();
2466
+ } else {
2467
+ this.remove();
2468
+ }
2469
+ return paths;
2470
+ }
2471
+ function replaceWithSourceString(replacement) {
2472
+ resync.call(this);
2168
2473
  let ast;
2169
2474
  try {
2170
2475
  replacement = `(${replacement})`;
@@ -2187,7 +2492,7 @@ function replaceWithSourceString(replacement) {
2187
2492
  return this.replaceWith(expressionAST);
2188
2493
  }
2189
2494
  function replaceWith(replacementPath) {
2190
- this.resync();
2495
+ resync.call(this);
2191
2496
  if (this.removed) {
2192
2497
  throw new Error("You can't replace this node, we've already removed it");
2193
2498
  }
@@ -2208,9 +2513,9 @@ function replaceWith(replacementPath) {
2208
2513
  throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
2209
2514
  }
2210
2515
  let nodePath = "";
2211
- if (this.isNodeType("Statement") && isExpression$2(replacement)) {
2516
+ if (this.isNodeType("Statement") && isExpression$1(replacement)) {
2212
2517
  if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
2213
- replacement = expressionStatement$2(replacement);
2518
+ replacement = expressionStatement$1(replacement);
2214
2519
  nodePath = "expression";
2215
2520
  }
2216
2521
  }
@@ -2224,9 +2529,9 @@ function replaceWith(replacementPath) {
2224
2529
  inheritsComments(replacement, oldNode);
2225
2530
  removeComments(oldNode);
2226
2531
  }
2227
- this._replaceWith(replacement);
2532
+ _replaceWith.call(this, replacement);
2228
2533
  this.type = replacement.type;
2229
- this.setScope();
2534
+ setScope.call(this);
2230
2535
  this.requeue();
2231
2536
  return [nodePath ? this.get(nodePath) : this];
2232
2537
  }
@@ -2244,7 +2549,7 @@ function _replaceWith(node) {
2244
2549
  this.node = this.container[this.key] = node;
2245
2550
  }
2246
2551
  function replaceExpressionWithStatements(nodes) {
2247
- this.resync();
2552
+ resync.call(this);
2248
2553
  const declars = [];
2249
2554
  const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);
2250
2555
  if (nodesAsSingleExpression) {
@@ -2254,17 +2559,15 @@ function replaceExpressionWithStatements(nodes) {
2254
2559
  return this.replaceWith(nodesAsSingleExpression)[0].get("expressions");
2255
2560
  }
2256
2561
  const functionParent = this.getFunctionParent();
2257
- const isParentAsync = functionParent?.is("async");
2258
- const isParentGenerator = functionParent?.is("generator");
2259
- const container = arrowFunctionExpression$2([], blockStatement$2(nodes));
2260
- this.replaceWith(callExpression$2(container, []));
2562
+ const isParentAsync = functionParent?.node.async;
2563
+ const isParentGenerator = functionParent?.node.generator;
2564
+ const container = arrowFunctionExpression$1([], blockStatement$1(nodes));
2565
+ this.replaceWith(callExpression$1(container, []));
2261
2566
  const callee = this.get("callee");
2262
- hoistVariables(callee.get("body"), id => {
2263
- this.scope.push({
2264
- id
2265
- });
2266
- }, "var");
2267
- const completionRecords = this.get("callee").getCompletionRecords();
2567
+ callee.get("body").scope.hoistVariables(id => this.scope.push({
2568
+ id
2569
+ }));
2570
+ const completionRecords = callee.getCompletionRecords();
2268
2571
  for (const path of completionRecords) {
2269
2572
  if (!path.isExpressionStatement()) continue;
2270
2573
  const loop = path.findParent(path => path.isLoop());
@@ -2272,12 +2575,12 @@ function replaceExpressionWithStatements(nodes) {
2272
2575
  let uid = loop.getData("expressionReplacementReturnUid");
2273
2576
  if (!uid) {
2274
2577
  uid = callee.scope.generateDeclaredUidIdentifier("ret");
2275
- callee.get("body").pushContainer("body", returnStatement$1(cloneNode$2(uid)));
2578
+ callee.get("body").pushContainer("body", returnStatement$1(cloneNode$1(uid)));
2276
2579
  loop.setData("expressionReplacementReturnUid", uid);
2277
2580
  } else {
2278
2581
  uid = identifier$1(uid.name);
2279
2582
  }
2280
- path.get("expression").replaceWith(assignmentExpression$2("=", cloneNode$2(uid), path.node.expression));
2583
+ path.get("expression").replaceWith(assignmentExpression$1("=", cloneNode$1(uid), path.node.expression));
2281
2584
  } else {
2282
2585
  path.replaceWith(returnStatement$1(path.node.expression));
2283
2586
  }
@@ -2305,19 +2608,19 @@ function gatherSequenceExpressions(nodes, declars) {
2305
2608
  if (!isEmptyStatement(node)) {
2306
2609
  ensureLastUndefined = false;
2307
2610
  }
2308
- if (isExpression$2(node)) {
2611
+ if (isExpression$1(node)) {
2309
2612
  exprs.push(node);
2310
2613
  } else if (isExpressionStatement(node)) {
2311
2614
  exprs.push(node.expression);
2312
2615
  } else if (isVariableDeclaration(node)) {
2313
2616
  if (node.kind !== "var") return;
2314
2617
  for (const declar of node.declarations) {
2315
- const bindings = getBindingIdentifiers$2(declar);
2618
+ const bindings = getBindingIdentifiers$1(declar);
2316
2619
  for (const key of Object.keys(bindings)) {
2317
- declars.push(cloneNode$2(bindings[key]));
2620
+ declars.push(cloneNode$1(bindings[key]));
2318
2621
  }
2319
2622
  if (declar.init) {
2320
- exprs.push(assignmentExpression$2("=", declar.id, declar.init));
2623
+ exprs.push(assignmentExpression$1("=", declar.id, declar.init));
2321
2624
  }
2322
2625
  }
2323
2626
  ensureLastUndefined = true;
@@ -2346,11 +2649,11 @@ function gatherSequenceExpressions(nodes, declars) {
2346
2649
  }
2347
2650
  }
2348
2651
  function replaceInline(nodes) {
2349
- this.resync();
2652
+ resync.call(this);
2350
2653
  if (Array.isArray(nodes)) {
2351
2654
  if (Array.isArray(this.container)) {
2352
- nodes = this._verifyNodeList(nodes);
2353
- const paths = this._containerInsertAfter(nodes);
2655
+ nodes = _verifyNodeList.call(this, nodes);
2656
+ const paths = _containerInsertAfter.call(this, nodes);
2354
2657
  this.remove();
2355
2658
  return paths;
2356
2659
  } else {
@@ -2701,15 +3004,15 @@ function evaluate() {
2701
3004
  }
2702
3005
 
2703
3006
  const {
2704
- arrowFunctionExpression: arrowFunctionExpression$1,
2705
- assignmentExpression: assignmentExpression$1,
3007
+ arrowFunctionExpression,
3008
+ assignmentExpression,
2706
3009
  binaryExpression,
2707
- blockStatement: blockStatement$1,
2708
- callExpression: callExpression$1,
3010
+ blockStatement,
3011
+ callExpression,
2709
3012
  conditionalExpression,
2710
- expressionStatement: expressionStatement$1,
3013
+ expressionStatement,
2711
3014
  identifier,
2712
- isIdentifier: isIdentifier$2,
3015
+ isIdentifier: isIdentifier$1,
2713
3016
  jsxIdentifier,
2714
3017
  logicalExpression,
2715
3018
  LOGICAL_OPERATORS,
@@ -2723,9 +3026,20 @@ const {
2723
3026
  spreadElement,
2724
3027
  stringLiteral,
2725
3028
  super: _super,
2726
- thisExpression: thisExpression$1,
3029
+ thisExpression,
2727
3030
  toExpression,
2728
- unaryExpression: unaryExpression$1
3031
+ unaryExpression: unaryExpression$1,
3032
+ toBindingIdentifierName,
3033
+ isFunction,
3034
+ isAssignmentPattern,
3035
+ isRestElement,
3036
+ getFunctionName,
3037
+ cloneNode,
3038
+ variableDeclaration,
3039
+ variableDeclarator,
3040
+ exportNamedDeclaration,
3041
+ exportSpecifier,
3042
+ inherits
2729
3043
  } = _t;
2730
3044
  function toComputedKey() {
2731
3045
  let key;
@@ -2737,7 +3051,7 @@ function toComputedKey() {
2737
3051
  throw new ReferenceError("todo");
2738
3052
  }
2739
3053
  if (!this.node.computed) {
2740
- if (isIdentifier$2(key)) key = stringLiteral(key.name);
3054
+ if (isIdentifier$1(key)) key = stringLiteral(key.name);
2741
3055
  }
2742
3056
  return key;
2743
3057
  }
@@ -2768,12 +3082,12 @@ function ensureBlock() {
2768
3082
  statements.push(returnStatement(body.node));
2769
3083
  } else {
2770
3084
  key = "expression";
2771
- statements.push(expressionStatement$1(body.node));
3085
+ statements.push(expressionStatement(body.node));
2772
3086
  }
2773
3087
  }
2774
- this.node.body = blockStatement$1(statements);
3088
+ this.node.body = blockStatement(statements);
2775
3089
  const parentPath = this.get(stringPath);
2776
- body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
3090
+ setup.call(body, parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
2777
3091
  return this.node;
2778
3092
  }
2779
3093
  function unwrapFunctionEnvironment() {
@@ -2793,10 +3107,14 @@ function arrowFunctionToExpression({
2793
3107
  if (!this.isArrowFunctionExpression()) {
2794
3108
  throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
2795
3109
  }
3110
+ let self = this;
3111
+ if (!noNewArrows) {
3112
+ self = self.ensureFunctionName(false) ?? self;
3113
+ }
2796
3114
  const {
2797
3115
  thisBinding,
2798
3116
  fnPath: fn
2799
- } = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow, allowInsertArrowWithRest);
3117
+ } = hoistFunctionEnvironment(self, noNewArrows, allowInsertArrow, allowInsertArrowWithRest);
2800
3118
  fn.ensureBlock();
2801
3119
  setType(fn, "FunctionExpression");
2802
3120
  if (!noNewArrows) {
@@ -2807,20 +3125,20 @@ function arrowFunctionToExpression({
2807
3125
  init: objectExpression([])
2808
3126
  });
2809
3127
  }
2810
- fn.get("body").unshiftContainer("body", expressionStatement$1(callExpression$1(this.hub.addHelper("newArrowCheck"), [thisExpression$1(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
2811
- fn.replaceWith(callExpression$1(memberExpression(nameFunction(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression$1()]));
3128
+ fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
3129
+ fn.replaceWith(callExpression(memberExpression(fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
2812
3130
  return fn.get("callee.object");
2813
3131
  }
2814
3132
  return fn;
2815
3133
  }
2816
- const getSuperCallsVisitor = merge([{
3134
+ const getSuperCallsVisitor = environmentVisitor({
2817
3135
  CallExpression(child, {
2818
3136
  allSuperCalls
2819
3137
  }) {
2820
3138
  if (!child.get("callee").isSuper()) return;
2821
3139
  allSuperCalls.push(child);
2822
3140
  }
2823
- }, environmentVisitor]);
3141
+ });
2824
3142
  function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true, allowInsertArrowWithRest = true) {
2825
3143
  let arrowParent;
2826
3144
  let thisEnvFn = fnPath.findParent(p => {
@@ -2841,7 +3159,7 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
2841
3159
  if (arrowParent) {
2842
3160
  thisEnvFn = arrowParent;
2843
3161
  } else if (allowInsertArrow) {
2844
- fnPath.replaceWith(callExpression$1(arrowFunctionExpression$1([], toExpression(fnPath.node)), []));
3162
+ fnPath.replaceWith(callExpression(arrowFunctionExpression([], toExpression(fnPath.node)), []));
2845
3163
  thisEnvFn = fnPath.get("callee");
2846
3164
  fnPath = thisEnvFn.get("body");
2847
3165
  } else {
@@ -2922,15 +3240,15 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
2922
3240
  const value = superParentPath.node.right;
2923
3241
  args.push(value);
2924
3242
  }
2925
- const call = callExpression$1(identifier(superBinding), args);
3243
+ const call = callExpression(identifier(superBinding), args);
2926
3244
  if (isCall) {
2927
- superParentPath.unshiftContainer("arguments", thisExpression$1());
3245
+ superParentPath.unshiftContainer("arguments", thisExpression());
2928
3246
  superProp.replaceWith(memberExpression(call, identifier("call")));
2929
3247
  thisPaths.push(superParentPath.get("arguments.0"));
2930
3248
  } else if (isAssignment) {
2931
3249
  superParentPath.replaceWith(call);
2932
3250
  } else if (isTaggedTemplate) {
2933
- superProp.replaceWith(callExpression$1(memberExpression(call, identifier("bind"), false), [thisExpression$1()]));
3251
+ superProp.replaceWith(callExpression(memberExpression(call, identifier("bind"), false), [thisExpression()]));
2934
3252
  thisPaths.push(superProp.get("arguments.0"));
2935
3253
  } else {
2936
3254
  superProp.replaceWith(call);
@@ -2967,7 +3285,7 @@ function standardizeSuperProperty(superProp) {
2967
3285
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
2968
3286
  const object = superProp.node.object;
2969
3287
  const property = superProp.node.property;
2970
- assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression$1("=", tmp, property), true));
3288
+ assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression("=", tmp, property), true));
2971
3289
  assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(tmp.name), true), value));
2972
3290
  } else {
2973
3291
  const object = superProp.node.object;
@@ -2985,7 +3303,7 @@ function standardizeSuperProperty(superProp) {
2985
3303
  const updateExpr = superProp.parentPath;
2986
3304
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
2987
3305
  const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
2988
- const parts = [assignmentExpression$1("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression$1("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression$1("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral$1(1)))];
3306
+ const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral$1(1)))];
2989
3307
  if (!superProp.parentPath.node.prefix) {
2990
3308
  parts.push(identifier(tmp.name));
2991
3309
  }
@@ -2997,7 +3315,7 @@ function standardizeSuperProperty(superProp) {
2997
3315
  return [superProp];
2998
3316
  function rightExpression(op, left, right) {
2999
3317
  if (op === "=") {
3000
- return assignmentExpression$1("=", left, right);
3318
+ return assignmentExpression("=", left, right);
3001
3319
  } else {
3002
3320
  return binaryExpression(op, left, right);
3003
3321
  }
@@ -3006,7 +3324,7 @@ function standardizeSuperProperty(superProp) {
3006
3324
  function hasSuperClass(thisEnvFn) {
3007
3325
  return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass;
3008
3326
  }
3009
- const assignSuperThisVisitor = merge([{
3327
+ const assignSuperThisVisitor = environmentVisitor({
3010
3328
  CallExpression(child, {
3011
3329
  supers,
3012
3330
  thisBinding
@@ -3014,12 +3332,12 @@ const assignSuperThisVisitor = merge([{
3014
3332
  if (!child.get("callee").isSuper()) return;
3015
3333
  if (supers.has(child.node)) return;
3016
3334
  supers.add(child.node);
3017
- child.replaceWithMultiple([child.node, assignmentExpression$1("=", identifier(thisBinding), identifier("this"))]);
3335
+ child.replaceWithMultiple([child.node, assignmentExpression("=", identifier(thisBinding), identifier("this"))]);
3018
3336
  }
3019
- }, environmentVisitor]);
3337
+ });
3020
3338
  function getThisBinding(thisEnvFn, inConstructor) {
3021
3339
  return getBinding(thisEnvFn, "this", thisBinding => {
3022
- if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression$1();
3340
+ if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression();
3023
3341
  thisEnvFn.traverse(assignSuperThisVisitor, {
3024
3342
  supers: new WeakSet(),
3025
3343
  thisBinding
@@ -3029,7 +3347,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
3029
3347
  function getSuperBinding(thisEnvFn) {
3030
3348
  return getBinding(thisEnvFn, "supercall", () => {
3031
3349
  const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
3032
- return arrowFunctionExpression$1([restElement(argsBinding)], callExpression$1(_super(), [spreadElement(identifier(argsBinding.name))]));
3350
+ return arrowFunctionExpression([restElement(argsBinding)], callExpression(_super(), [spreadElement(identifier(argsBinding.name))]));
3033
3351
  });
3034
3352
  }
3035
3353
  function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
@@ -3047,9 +3365,9 @@ function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
3047
3365
  if (isAssignment) {
3048
3366
  const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
3049
3367
  argsList.push(valueIdent);
3050
- fnBody = assignmentExpression$1("=", fnBody, identifier(valueIdent.name));
3368
+ fnBody = assignmentExpression("=", fnBody, identifier(valueIdent.name));
3051
3369
  }
3052
- return arrowFunctionExpression$1(argsList, fnBody);
3370
+ return arrowFunctionExpression(argsList, fnBody);
3053
3371
  });
3054
3372
  }
3055
3373
  function getBinding(thisEnvFn, key, init) {
@@ -3066,7 +3384,7 @@ function getBinding(thisEnvFn, key, init) {
3066
3384
  }
3067
3385
  return data;
3068
3386
  }
3069
- const getScopeInformationVisitor = merge([{
3387
+ const getScopeInformationVisitor = environmentVisitor({
3070
3388
  ThisExpression(child, {
3071
3389
  thisPaths
3072
3390
  }) {
@@ -3124,7 +3442,7 @@ const getScopeInformationVisitor = merge([{
3124
3442
  })) return;
3125
3443
  newTargetPaths.push(child);
3126
3444
  }
3127
- }, environmentVisitor]);
3445
+ });
3128
3446
  function getScopeInformation(fnPath) {
3129
3447
  const thisPaths = [];
3130
3448
  const argumentsPaths = [];
@@ -3146,53 +3464,161 @@ function getScopeInformation(fnPath) {
3146
3464
  superCalls
3147
3465
  };
3148
3466
  }
3149
-
3150
- const {
3151
- STATEMENT_OR_BLOCK_KEYS,
3152
- VISITOR_KEYS: VISITOR_KEYS$3,
3153
- isBlockStatement,
3154
- isExpression: isExpression$1,
3155
- isIdentifier: isIdentifier$1,
3156
- isLiteral,
3157
- isStringLiteral,
3158
- isType,
3159
- matchesPattern: _matchesPattern
3160
- } = _t;
3161
- function matchesPattern(pattern, allowPartial) {
3162
- return _matchesPattern(this.node, pattern, allowPartial);
3163
- }
3164
- function has(key) {
3165
- const val = this.node?.[key];
3166
- if (val && Array.isArray(val)) {
3167
- return !!val.length;
3168
- } else {
3169
- return !!val;
3467
+ function splitExportDeclaration() {
3468
+ if (!this.isExportDeclaration() || this.isExportAllDeclaration()) {
3469
+ throw new Error("Only default and named export declarations can be split.");
3470
+ }
3471
+ if (this.isExportNamedDeclaration() && this.get("specifiers").length > 0) {
3472
+ throw new Error("It doesn't make sense to split exported specifiers.");
3473
+ }
3474
+ const declaration = this.get("declaration");
3475
+ if (this.isExportDefaultDeclaration()) {
3476
+ const standaloneDeclaration = declaration.isFunctionDeclaration() || declaration.isClassDeclaration();
3477
+ const exportExpr = declaration.isFunctionExpression() || declaration.isClassExpression();
3478
+ const scope = declaration.isScope() ? declaration.scope.parent : declaration.scope;
3479
+ let id = declaration.node.id;
3480
+ let needBindingRegistration = false;
3481
+ if (!id) {
3482
+ needBindingRegistration = true;
3483
+ id = scope.generateUidIdentifier("default");
3484
+ if (standaloneDeclaration || exportExpr) {
3485
+ declaration.node.id = cloneNode(id);
3486
+ }
3487
+ } else if (exportExpr && scope.hasBinding(id.name)) {
3488
+ needBindingRegistration = true;
3489
+ id = scope.generateUidIdentifier(id.name);
3490
+ }
3491
+ const updatedDeclaration = standaloneDeclaration ? declaration.node : variableDeclaration("var", [variableDeclarator(cloneNode(id), declaration.node)]);
3492
+ const updatedExportDeclaration = exportNamedDeclaration(null, [exportSpecifier(cloneNode(id), identifier("default"))]);
3493
+ this.insertAfter(updatedExportDeclaration);
3494
+ this.replaceWith(updatedDeclaration);
3495
+ if (needBindingRegistration) {
3496
+ scope.registerDeclaration(this);
3497
+ }
3498
+ return this;
3499
+ } else if (this.get("specifiers").length > 0) {
3500
+ throw new Error("It doesn't make sense to split exported specifiers.");
3170
3501
  }
3502
+ const bindingIdentifiers = declaration.getOuterBindingIdentifiers();
3503
+ const specifiers = Object.keys(bindingIdentifiers).map(name => {
3504
+ return exportSpecifier(identifier(name), identifier(name));
3505
+ });
3506
+ const aliasDeclar = exportNamedDeclaration(null, specifiers);
3507
+ this.insertAfter(aliasDeclar);
3508
+ this.replaceWith(declaration.node);
3509
+ return this;
3171
3510
  }
3172
- function isStatic() {
3173
- return this.scope.isStatic(this.node);
3174
- }
3175
- const is = has;
3176
- function isnt(key) {
3177
- return !this.has(key);
3178
- }
3179
- function equals(key, value) {
3180
- return this.node[key] === value;
3181
- }
3182
- function isNodeType(type) {
3183
- return isType(this.type, type);
3184
- }
3185
- function canHaveVariableDeclarationOrExpression() {
3186
- return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
3187
- }
3188
- function canSwapBetweenExpressionAndStatement(replacement) {
3189
- if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
3511
+ const refersOuterBindingVisitor = {
3512
+ "ReferencedIdentifier|BindingIdentifier"(path, state) {
3513
+ if (path.node.name !== state.name) return;
3514
+ state.needsRename = true;
3515
+ path.stop();
3516
+ },
3517
+ Scope(path, state) {
3518
+ if (path.scope.hasOwnBinding(state.name)) {
3519
+ path.skip();
3520
+ }
3521
+ }
3522
+ };
3523
+ function ensureFunctionName(supportUnicodeId) {
3524
+ if (this.node.id) return this;
3525
+ const res = getFunctionName(this.node, this.parent);
3526
+ if (res == null) return this;
3527
+ let {
3528
+ name
3529
+ } = res;
3530
+ if (!supportUnicodeId && /[\uD800-\uDFFF]/.test(name)) {
3531
+ return null;
3532
+ }
3533
+ if (name.startsWith("get ") || name.startsWith("set ")) {
3534
+ return null;
3535
+ }
3536
+ name = toBindingIdentifierName(name.replace(/[/ ]/g, "_"));
3537
+ const id = identifier(name);
3538
+ inherits(id, res.originalNode);
3539
+ const state = {
3540
+ needsRename: false,
3541
+ name
3542
+ };
3543
+ const {
3544
+ scope
3545
+ } = this;
3546
+ const binding = scope.getOwnBinding(name);
3547
+ if (binding) {
3548
+ if (binding.kind === "param") {
3549
+ state.needsRename = true;
3550
+ }
3551
+ } else if (scope.parent.hasBinding(name) || scope.hasGlobal(name)) {
3552
+ this.traverse(refersOuterBindingVisitor, state);
3553
+ }
3554
+ if (!state.needsRename) {
3555
+ this.node.id = id;
3556
+ scope.getProgramParent().references[id.name] = true;
3557
+ return this;
3558
+ }
3559
+ if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
3560
+ scope.rename(id.name);
3561
+ this.node.id = id;
3562
+ scope.getProgramParent().references[id.name] = true;
3563
+ return this;
3564
+ }
3565
+ if (!isFunction(this.node)) return null;
3566
+ const key = scope.generateUidIdentifier(id.name);
3567
+ const params = [];
3568
+ for (let i = 0, len = getFunctionArity(this.node); i < len; i++) {
3569
+ params.push(scope.generateUidIdentifier("x"));
3570
+ }
3571
+ const call = template.expression.ast`
3572
+ (function (${key}) {
3573
+ function ${id}(${params}) {
3574
+ return ${cloneNode(key)}.apply(this, arguments);
3575
+ }
3576
+
3577
+ ${cloneNode(id)}.toString = function () {
3578
+ return ${cloneNode(key)}.toString();
3579
+ }
3580
+
3581
+ return ${cloneNode(id)};
3582
+ })(${toExpression(this.node)})
3583
+ `;
3584
+ return this.replaceWith(call)[0].get("arguments.0");
3585
+ }
3586
+ function getFunctionArity(node) {
3587
+ const count = node.params.findIndex(param => isAssignmentPattern(param) || isRestElement(param));
3588
+ return count === -1 ? node.params.length : count;
3589
+ }
3590
+
3591
+ const {
3592
+ STATEMENT_OR_BLOCK_KEYS,
3593
+ VISITOR_KEYS: VISITOR_KEYS$3,
3594
+ isBlockStatement,
3595
+ isExpression,
3596
+ isIdentifier,
3597
+ isLiteral,
3598
+ isStringLiteral,
3599
+ isType,
3600
+ matchesPattern: _matchesPattern
3601
+ } = _t;
3602
+ function matchesPattern(pattern, allowPartial) {
3603
+ return _matchesPattern(this.node, pattern, allowPartial);
3604
+ }
3605
+ function isStatic() {
3606
+ return this.scope.isStatic(this.node);
3607
+ }
3608
+ function isNodeType(type) {
3609
+ return isType(this.type, type);
3610
+ }
3611
+ function canHaveVariableDeclarationOrExpression() {
3612
+ return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
3613
+ }
3614
+ function canSwapBetweenExpressionAndStatement(replacement) {
3615
+ if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
3190
3616
  return false;
3191
3617
  }
3192
3618
  if (this.isExpression()) {
3193
3619
  return isBlockStatement(replacement);
3194
3620
  } else if (this.isBlockStatement()) {
3195
- return isExpression$1(replacement);
3621
+ return isExpression(replacement);
3196
3622
  }
3197
3623
  return false;
3198
3624
  }
@@ -3247,7 +3673,7 @@ function referencesImport(moduleSource, importName) {
3247
3673
  if (path.isImportNamespaceSpecifier() && importName === "*") {
3248
3674
  return true;
3249
3675
  }
3250
- if (path.isImportSpecifier() && isIdentifier$1(path.node.imported, {
3676
+ if (path.isImportSpecifier() && isIdentifier(path.node.imported, {
3251
3677
  name: importName
3252
3678
  })) {
3253
3679
  return true;
@@ -3321,8 +3747,8 @@ function _guessExecutionStatusRelativeToCached(base, target, cache) {
3321
3747
  target: target.getAncestry(),
3322
3748
  this: base.getAncestry()
3323
3749
  };
3324
- if (paths.target.indexOf(base) >= 0) return "after";
3325
- if (paths.this.indexOf(target) >= 0) return "before";
3750
+ if (paths.target.includes(base)) return "after";
3751
+ if (paths.this.includes(target)) return "before";
3326
3752
  let commonPath;
3327
3753
  const commonIndex = {
3328
3754
  target: 0,
@@ -3402,10 +3828,10 @@ function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, c
3402
3828
  return result;
3403
3829
  }
3404
3830
  function resolve(dangerous, resolved) {
3405
- return this._resolve(dangerous, resolved) || this;
3831
+ return _resolve.call(this, dangerous, resolved) || this;
3406
3832
  }
3407
3833
  function _resolve(dangerous, resolved) {
3408
- if (resolved && resolved.indexOf(this) >= 0) return;
3834
+ if (resolved?.includes(this)) return;
3409
3835
  resolved = resolved || [];
3410
3836
  resolved.push(this);
3411
3837
  if (this.isVariableDeclarator()) {
@@ -3486,673 +3912,39 @@ function isConstantExpression() {
3486
3912
  if (this.isCallExpression()) {
3487
3913
  return this.node.arguments.length === 1 && this.get("callee").matchesPattern("Symbol.for") && !this.scope.hasBinding("Symbol", {
3488
3914
  noGlobals: true
3489
- }) && this.get("arguments")[0].isStringLiteral();
3490
- }
3491
- return false;
3492
- }
3493
- function isInStrictMode() {
3494
- const start = this.isProgram() ? this : this.parentPath;
3495
- const strictParent = start.find(path => {
3496
- if (path.isProgram({
3497
- sourceType: "module"
3498
- })) return true;
3499
- if (path.isClass()) return true;
3500
- if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
3501
- return false;
3502
- }
3503
- let body;
3504
- if (path.isFunction()) {
3505
- body = path.node.body;
3506
- } else if (path.isProgram()) {
3507
- body = path.node;
3508
- } else {
3509
- return false;
3510
- }
3511
- for (const directive of body.directives) {
3512
- if (directive.value.value === "use strict") {
3513
- return true;
3514
- }
3515
- }
3516
- });
3517
- return !!strictParent;
3518
- }
3519
-
3520
- function call(key) {
3521
- const opts = this.opts;
3522
- this.debug(key);
3523
- if (this.node) {
3524
- if (this._call(opts[key])) return true;
3525
- }
3526
- if (this.node) {
3527
- return this._call(opts[this.node.type]?.[key]);
3528
- }
3529
- return false;
3530
- }
3531
- function _call(fns) {
3532
- if (!fns) return false;
3533
- for (const fn of fns) {
3534
- if (!fn) continue;
3535
- const node = this.node;
3536
- if (!node) return true;
3537
- const ret = fn.call(this.state, this, this.state);
3538
- if (ret && typeof ret === "object" && typeof ret.then === "function") {
3539
- throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
3540
- }
3541
- if (ret) {
3542
- throw new Error(`Unexpected return value from visitor method ${fn}`);
3543
- }
3544
- if (this.node !== node) return true;
3545
- if (this._traverseFlags > 0) return true;
3546
- }
3547
- return false;
3548
- }
3549
- function isDenylisted() {
3550
- const denylist = this.opts.denylist ?? this.opts.blacklist;
3551
- return denylist && denylist.indexOf(this.node.type) > -1;
3552
- }
3553
- function restoreContext(path, context) {
3554
- if (path.context !== context) {
3555
- path.context = context;
3556
- path.state = context.state;
3557
- path.opts = context.opts;
3558
- }
3559
- }
3560
- function visit() {
3561
- if (!this.node) {
3562
- return false;
3563
- }
3564
- if (this.isDenylisted()) {
3565
- return false;
3566
- }
3567
- if (this.opts.shouldSkip?.(this)) {
3568
- return false;
3569
- }
3570
- const currentContext = this.context;
3571
- if (this.shouldSkip || this.call("enter")) {
3572
- this.debug("Skip...");
3573
- return this.shouldStop;
3574
- }
3575
- restoreContext(this, currentContext);
3576
- this.debug("Recursing into...");
3577
- this.shouldStop = traverseNode(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
3578
- restoreContext(this, currentContext);
3579
- this.call("exit");
3580
- return this.shouldStop;
3581
- }
3582
- function skip() {
3583
- this.shouldSkip = true;
3584
- }
3585
- function skipKey(key) {
3586
- if (this.skipKeys == null) {
3587
- this.skipKeys = {};
3588
- }
3589
- this.skipKeys[key] = true;
3590
- }
3591
- function stop() {
3592
- this._traverseFlags |= SHOULD_SKIP | SHOULD_STOP;
3593
- }
3594
- function setScope() {
3595
- if (this.opts?.noScope) return;
3596
- let path = this.parentPath;
3597
- if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {
3598
- path = path.parentPath;
3599
- }
3600
- let target;
3601
- while (path && !target) {
3602
- if (path.opts?.noScope) return;
3603
- target = path.scope;
3604
- path = path.parentPath;
3605
- }
3606
- this.scope = this.getScope(target);
3607
- this.scope?.init();
3608
- }
3609
- function setContext(context) {
3610
- if (this.skipKeys != null) {
3611
- this.skipKeys = {};
3612
- }
3613
- this._traverseFlags = 0;
3614
- if (context) {
3615
- this.context = context;
3616
- this.state = context.state;
3617
- this.opts = context.opts;
3618
- }
3619
- this.setScope();
3620
- return this;
3621
- }
3622
- function resync() {
3623
- if (this.removed) return;
3624
- this._resyncParent();
3625
- this._resyncList();
3626
- this._resyncKey();
3627
- }
3628
- function _resyncParent() {
3629
- if (this.parentPath) {
3630
- this.parent = this.parentPath.node;
3631
- }
3632
- }
3633
- function _resyncKey() {
3634
- if (!this.container) return;
3635
- if (this.node === this.container[this.key]) {
3636
- return;
3637
- }
3638
- if (Array.isArray(this.container)) {
3639
- for (let i = 0; i < this.container.length; i++) {
3640
- if (this.container[i] === this.node) {
3641
- this.setKey(i);
3642
- return;
3643
- }
3644
- }
3645
- } else {
3646
- for (const key of Object.keys(this.container)) {
3647
- if (this.container[key] === this.node) {
3648
- this.setKey(key);
3649
- return;
3650
- }
3651
- }
3652
- }
3653
- this.key = null;
3654
- }
3655
- function _resyncList() {
3656
- if (!this.parent || !this.inList) return;
3657
- const newContainer = this.parent[this.listKey];
3658
- if (this.container === newContainer) return;
3659
- this.container = newContainer || null;
3660
- }
3661
- function _resyncRemoved() {
3662
- if (this.key == null || !this.container || this.container[this.key] !== this.node) {
3663
- this._markRemoved();
3664
- }
3665
- }
3666
- function popContext() {
3667
- this.contexts.pop();
3668
- if (this.contexts.length > 0) {
3669
- this.setContext(this.contexts[this.contexts.length - 1]);
3670
- } else {
3671
- this.setContext(undefined);
3672
- }
3673
- }
3674
- function pushContext(context) {
3675
- this.contexts.push(context);
3676
- this.setContext(context);
3677
- }
3678
- function setup(parentPath, container, listKey, key) {
3679
- this.listKey = listKey;
3680
- this.container = container;
3681
- this.parentPath = parentPath || this.parentPath;
3682
- this.setKey(key);
3683
- }
3684
- function setKey(key) {
3685
- this.key = key;
3686
- this.node = this.container[this.key];
3687
- this.type = this.node?.type;
3688
- }
3689
- function requeue(pathToQueue = this) {
3690
- if (pathToQueue.removed) return;
3691
- {
3692
- pathToQueue.shouldSkip = false;
3693
- }
3694
- const contexts = this.contexts;
3695
- for (const context of contexts) {
3696
- context.maybeQueue(pathToQueue);
3697
- }
3698
- }
3699
- function _getQueueContexts() {
3700
- let path = this;
3701
- let contexts = this.contexts;
3702
- while (!contexts.length) {
3703
- path = path.parentPath;
3704
- if (!path) break;
3705
- contexts = path.contexts;
3706
- }
3707
- return contexts;
3708
- }
3709
-
3710
- const hooks = [function (self, parent) {
3711
- const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
3712
- if (removeParent) {
3713
- parent.remove();
3714
- return true;
3715
- }
3716
- }, function (self, parent) {
3717
- if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
3718
- parent.replaceWith(parent.node.expressions[0]);
3719
- return true;
3720
- }
3721
- }, function (self, parent) {
3722
- if (parent.isBinary()) {
3723
- if (self.key === "left") {
3724
- parent.replaceWith(parent.node.right);
3725
- } else {
3726
- parent.replaceWith(parent.node.left);
3727
- }
3728
- return true;
3729
- }
3730
- }, function (self, parent) {
3731
- if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
3732
- self.replaceWith({
3733
- type: "BlockStatement",
3734
- body: []
3735
- });
3736
- return true;
3737
- }
3738
- }];
3739
-
3740
- const {
3741
- getBindingIdentifiers: getBindingIdentifiers$1
3742
- } = _t;
3743
- function remove() {
3744
- this._assertUnremoved();
3745
- this.resync();
3746
- if (!this.opts?.noScope) {
3747
- this._removeFromScope();
3748
- }
3749
- if (this._callRemovalHooks()) {
3750
- this._markRemoved();
3751
- return;
3752
- }
3753
- this.shareCommentsWithSiblings();
3754
- this._remove();
3755
- this._markRemoved();
3756
- }
3757
- function _removeFromScope() {
3758
- const bindings = getBindingIdentifiers$1(this.node, false, false, true);
3759
- Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
3760
- }
3761
- function _callRemovalHooks() {
3762
- if (this.parentPath) {
3763
- for (const fn of hooks) {
3764
- if (fn(this, this.parentPath)) return true;
3765
- }
3766
- }
3767
- }
3768
- function _remove() {
3769
- if (Array.isArray(this.container)) {
3770
- this.container.splice(this.key, 1);
3771
- this.updateSiblingKeys(this.key, -1);
3772
- } else {
3773
- this._replaceWith(null);
3774
- }
3775
- }
3776
- function _markRemoved() {
3777
- this._traverseFlags |= SHOULD_SKIP | REMOVED;
3778
- if (this.parent) {
3779
- getCachedPaths(this.hub, this.parent).delete(this.node);
3780
- }
3781
- this.node = null;
3782
- }
3783
- function _assertUnremoved() {
3784
- if (this.removed) {
3785
- throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
3786
- }
3787
- }
3788
-
3789
- const {
3790
- react
3791
- } = _t;
3792
- const {
3793
- cloneNode: cloneNode$1,
3794
- jsxExpressionContainer,
3795
- variableDeclaration,
3796
- variableDeclarator
3797
- } = _t;
3798
- const referenceVisitor = {
3799
- ReferencedIdentifier(path, state) {
3800
- if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
3801
- return;
3802
- }
3803
- if (path.node.name === "this") {
3804
- let scope = path.scope;
3805
- do {
3806
- if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
3807
- break;
3808
- }
3809
- } while (scope = scope.parent);
3810
- if (scope) state.breakOnScopePaths.push(scope.path);
3811
- }
3812
- const binding = path.scope.getBinding(path.node.name);
3813
- if (!binding) return;
3814
- for (const violation of binding.constantViolations) {
3815
- if (violation.scope !== binding.path.scope) {
3816
- state.mutableBinding = true;
3817
- path.stop();
3818
- return;
3819
- }
3820
- }
3821
- if (binding !== state.scope.getBinding(path.node.name)) return;
3822
- state.bindings[path.node.name] = binding;
3823
- }
3824
- };
3825
- class PathHoister {
3826
- breakOnScopePaths;
3827
- bindings;
3828
- mutableBinding;
3829
- scopes;
3830
- scope;
3831
- path;
3832
- attachAfter;
3833
- constructor(path, scope) {
3834
- this.breakOnScopePaths = [];
3835
- this.bindings = {};
3836
- this.mutableBinding = false;
3837
- this.scopes = [];
3838
- this.scope = scope;
3839
- this.path = path;
3840
- this.attachAfter = false;
3841
- }
3842
- isCompatibleScope(scope) {
3843
- for (const key of Object.keys(this.bindings)) {
3844
- const binding = this.bindings[key];
3845
- if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
3846
- return false;
3847
- }
3848
- }
3849
- return true;
3850
- }
3851
- getCompatibleScopes() {
3852
- let scope = this.path.scope;
3853
- do {
3854
- if (this.isCompatibleScope(scope)) {
3855
- this.scopes.push(scope);
3856
- } else {
3857
- break;
3858
- }
3859
- if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
3860
- break;
3861
- }
3862
- } while (scope = scope.parent);
3863
- }
3864
- getAttachmentPath() {
3865
- let path = this._getAttachmentPath();
3866
- if (!path) return;
3867
- let targetScope = path.scope;
3868
- if (targetScope.path === path) {
3869
- targetScope = path.scope.parent;
3870
- }
3871
- if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
3872
- for (const name of Object.keys(this.bindings)) {
3873
- if (!targetScope.hasOwnBinding(name)) continue;
3874
- const binding = this.bindings[name];
3875
- if (binding.kind === "param" || binding.path.parentKey === "params") {
3876
- continue;
3877
- }
3878
- const bindingParentPath = this.getAttachmentParentForPath(binding.path);
3879
- if (bindingParentPath.key >= path.key) {
3880
- this.attachAfter = true;
3881
- path = binding.path;
3882
- for (const violationPath of binding.constantViolations) {
3883
- if (this.getAttachmentParentForPath(violationPath).key > path.key) {
3884
- path = violationPath;
3885
- }
3886
- }
3887
- }
3888
- }
3889
- }
3890
- return path;
3891
- }
3892
- _getAttachmentPath() {
3893
- const scopes = this.scopes;
3894
- const scope = scopes.pop();
3895
- if (!scope) return;
3896
- if (scope.path.isFunction()) {
3897
- if (this.hasOwnParamBindings(scope)) {
3898
- if (this.scope === scope) return;
3899
- const bodies = scope.path.get("body").get("body");
3900
- for (let i = 0; i < bodies.length; i++) {
3901
- if (bodies[i].node._blockHoist) continue;
3902
- return bodies[i];
3903
- }
3904
- } else {
3905
- return this.getNextScopeAttachmentParent();
3906
- }
3907
- } else if (scope.path.isProgram()) {
3908
- return this.getNextScopeAttachmentParent();
3909
- }
3910
- }
3911
- getNextScopeAttachmentParent() {
3912
- const scope = this.scopes.pop();
3913
- if (scope) return this.getAttachmentParentForPath(scope.path);
3914
- }
3915
- getAttachmentParentForPath(path) {
3916
- do {
3917
- if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
3918
- return path;
3919
- }
3920
- } while (path = path.parentPath);
3921
- }
3922
- hasOwnParamBindings(scope) {
3923
- for (const name of Object.keys(this.bindings)) {
3924
- if (!scope.hasOwnBinding(name)) continue;
3925
- const binding = this.bindings[name];
3926
- if (binding.kind === "param" && binding.constant) return true;
3927
- }
3928
- return false;
3929
- }
3930
- run() {
3931
- this.path.traverse(referenceVisitor, this);
3932
- if (this.mutableBinding) return;
3933
- this.getCompatibleScopes();
3934
- const attachTo = this.getAttachmentPath();
3935
- if (!attachTo) return;
3936
- if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
3937
- let uid = attachTo.scope.generateUidIdentifier("ref");
3938
- const declarator = variableDeclarator(uid, this.path.node);
3939
- const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
3940
- const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : variableDeclaration("var", [declarator])]);
3941
- const parent = this.path.parentPath;
3942
- if (parent.isJSXElement() && this.path.container === parent.node.children) {
3943
- uid = jsxExpressionContainer(uid);
3944
- }
3945
- this.path.replaceWith(cloneNode$1(uid));
3946
- return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
3947
- }
3948
- }
3949
-
3950
- const {
3951
- arrowFunctionExpression,
3952
- assertExpression,
3953
- assignmentExpression,
3954
- blockStatement,
3955
- callExpression,
3956
- cloneNode,
3957
- expressionStatement,
3958
- isAssignmentExpression,
3959
- isCallExpression,
3960
- isExportNamedDeclaration,
3961
- isExpression,
3962
- isIdentifier,
3963
- isSequenceExpression,
3964
- isSuper,
3965
- thisExpression
3966
- } = _t;
3967
- function insertBefore(nodes_) {
3968
- this._assertUnremoved();
3969
- const nodes = this._verifyNodeList(nodes_);
3970
- const {
3971
- parentPath,
3972
- parent
3973
- } = this;
3974
- if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
3975
- return parentPath.insertBefore(nodes);
3976
- } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
3977
- if (this.node) nodes.push(this.node);
3978
- return this.replaceExpressionWithStatements(nodes);
3979
- } else if (Array.isArray(this.container)) {
3980
- return this._containerInsertBefore(nodes);
3981
- } else if (this.isStatementOrBlock()) {
3982
- const node = this.node;
3983
- const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
3984
- this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
3985
- return this.unshiftContainer("body", nodes);
3986
- } else {
3987
- throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
3988
- }
3989
- }
3990
- function _containerInsert(from, nodes) {
3991
- this.updateSiblingKeys(from, nodes.length);
3992
- const paths = [];
3993
- this.container.splice(from, 0, ...nodes);
3994
- for (let i = 0; i < nodes.length; i++) {
3995
- const to = from + i;
3996
- const path = this.getSibling(to);
3997
- paths.push(path);
3998
- if (this.context?.queue) {
3999
- path.pushContext(this.context);
4000
- }
4001
- }
4002
- const contexts = this._getQueueContexts();
4003
- for (const path of paths) {
4004
- path.setScope();
4005
- path.debug("Inserted.");
4006
- for (const context of contexts) {
4007
- context.maybeQueue(path, true);
4008
- }
4009
- }
4010
- return paths;
4011
- }
4012
- function _containerInsertBefore(nodes) {
4013
- return this._containerInsert(this.key, nodes);
4014
- }
4015
- function _containerInsertAfter(nodes) {
4016
- return this._containerInsert(this.key + 1, nodes);
4017
- }
4018
- const last = arr => arr[arr.length - 1];
4019
- function isHiddenInSequenceExpression(path) {
4020
- return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
4021
- }
4022
- function isAlmostConstantAssignment(node, scope) {
4023
- if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
4024
- return false;
4025
- }
4026
- const blockScope = scope.getBlockParent();
4027
- return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
4028
- }
4029
- function insertAfter(nodes_) {
4030
- this._assertUnremoved();
4031
- if (this.isSequenceExpression()) {
4032
- return last(this.get("expressions")).insertAfter(nodes_);
4033
- }
4034
- const nodes = this._verifyNodeList(nodes_);
4035
- const {
4036
- parentPath,
4037
- parent
4038
- } = this;
4039
- if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
4040
- return parentPath.insertAfter(nodes.map(node => {
4041
- return isExpression(node) ? expressionStatement(node) : node;
4042
- }));
4043
- } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
4044
- const self = this;
4045
- if (self.node) {
4046
- const node = self.node;
4047
- let {
4048
- scope
4049
- } = this;
4050
- if (scope.path.isPattern()) {
4051
- assertExpression(node);
4052
- self.replaceWith(callExpression(arrowFunctionExpression([], node), []));
4053
- self.get("callee.body").insertAfter(nodes);
4054
- return [self];
4055
- }
4056
- if (isHiddenInSequenceExpression(self)) {
4057
- nodes.unshift(node);
4058
- } else if (isCallExpression(node) && isSuper(node.callee)) {
4059
- nodes.unshift(node);
4060
- nodes.push(thisExpression());
4061
- } else if (isAlmostConstantAssignment(node, scope)) {
4062
- nodes.unshift(node);
4063
- nodes.push(cloneNode(node.left));
4064
- } else if (scope.isPure(node, true)) {
4065
- nodes.push(node);
4066
- } else {
4067
- if (parentPath.isMethod({
4068
- computed: true,
4069
- key: node
4070
- })) {
4071
- scope = scope.parent;
4072
- }
4073
- const temp = scope.generateDeclaredUidIdentifier();
4074
- nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
4075
- nodes.push(expressionStatement(cloneNode(temp)));
4076
- }
4077
- }
4078
- return this.replaceExpressionWithStatements(nodes);
4079
- } else if (Array.isArray(this.container)) {
4080
- return this._containerInsertAfter(nodes);
4081
- } else if (this.isStatementOrBlock()) {
4082
- const node = this.node;
4083
- const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
4084
- this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
4085
- return this.pushContainer("body", nodes);
4086
- } else {
4087
- throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
3915
+ }) && this.get("arguments")[0].isStringLiteral();
4088
3916
  }
3917
+ return false;
4089
3918
  }
4090
- function updateSiblingKeys(fromIndex, incrementBy) {
4091
- if (!this.parent) return;
4092
- const paths = getCachedPaths(this.hub, this.parent) || [];
4093
- for (const [, path] of paths) {
4094
- if (typeof path.key === "number" && path.key >= fromIndex) {
4095
- path.key += incrementBy;
3919
+ function isInStrictMode() {
3920
+ const start = this.isProgram() ? this : this.parentPath;
3921
+ const strictParent = start.find(path => {
3922
+ if (path.isProgram({
3923
+ sourceType: "module"
3924
+ })) return true;
3925
+ if (path.isClass()) return true;
3926
+ if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
3927
+ return false;
4096
3928
  }
4097
- }
4098
- }
4099
- function _verifyNodeList(nodes) {
4100
- if (!nodes) {
4101
- return [];
4102
- }
4103
- if (!Array.isArray(nodes)) {
4104
- nodes = [nodes];
4105
- }
4106
- for (let i = 0; i < nodes.length; i++) {
4107
- const node = nodes[i];
4108
- let msg;
4109
- if (!node) {
4110
- msg = "has falsy node";
4111
- } else if (typeof node !== "object") {
4112
- msg = "contains a non-object node";
4113
- } else if (!node.type) {
4114
- msg = "without a type";
4115
- } else if (node instanceof NodePath_Final) {
4116
- msg = "has a NodePath when it expected a raw object";
3929
+ let body;
3930
+ if (path.isFunction()) {
3931
+ body = path.node.body;
3932
+ } else if (path.isProgram()) {
3933
+ body = path.node;
3934
+ } else {
3935
+ return false;
4117
3936
  }
4118
- if (msg) {
4119
- const type = Array.isArray(node) ? "array" : typeof node;
4120
- throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
3937
+ for (const directive of body.directives) {
3938
+ if (directive.value.value === "use strict") {
3939
+ return true;
3940
+ }
4121
3941
  }
4122
- }
4123
- return nodes;
4124
- }
4125
- function unshiftContainer(listKey, nodes) {
4126
- this._assertUnremoved();
4127
- nodes = this._verifyNodeList(nodes);
4128
- const path = NodePath_Final.get({
4129
- parentPath: this,
4130
- parent: this.node,
4131
- container: this.node[listKey],
4132
- listKey,
4133
- key: 0
4134
- }).setContext(this.context);
4135
- return path._containerInsertBefore(nodes);
4136
- }
4137
- function pushContainer(listKey, nodes) {
4138
- this._assertUnremoved();
4139
- const verifiedNodes = this._verifyNodeList(nodes);
4140
- const container = this.node[listKey];
4141
- const path = NodePath_Final.get({
4142
- parentPath: this,
4143
- parent: this.node,
4144
- container: container,
4145
- listKey,
4146
- key: container.length
4147
- }).setContext(this.context);
4148
- return path.replaceWithMultiple(verifiedNodes);
4149
- }
4150
- function hoist(scope = this.scope) {
4151
- const hoister = new PathHoister(this, scope);
4152
- return hoister.run();
3942
+ });
3943
+ return !!strictParent;
4153
3944
  }
4154
3945
 
4155
3946
  const {
3947
+ getAssignmentIdentifiers: _getAssignmentIdentifiers,
4156
3948
  getBindingIdentifiers: _getBindingIdentifiers,
4157
3949
  getOuterBindingIdentifiers: _getOuterBindingIdentifiers,
4158
3950
  numericLiteral,
@@ -4365,9 +4157,9 @@ function get(key, context = true) {
4365
4157
  if (context === true) context = this.context;
4366
4158
  const parts = key.split(".");
4367
4159
  if (parts.length === 1) {
4368
- return this._getKey(key, context);
4160
+ return _getKey.call(this, key, context);
4369
4161
  } else {
4370
- return this._getPattern(parts, context);
4162
+ return _getPattern.call(this, parts, context);
4371
4163
  }
4372
4164
  }
4373
4165
  function _getKey(key, context) {
@@ -4407,6 +4199,9 @@ function _getPattern(parts, context) {
4407
4199
  }
4408
4200
  return path;
4409
4201
  }
4202
+ function getAssignmentIdentifiers() {
4203
+ return _getAssignmentIdentifiers(this.node);
4204
+ }
4410
4205
  function getBindingIdentifiers(duplicates) {
4411
4206
  return _getBindingIdentifiers(this.node, duplicates);
4412
4207
  }
@@ -4572,7 +4367,7 @@ const NodePath_Final = class NodePath {
4572
4367
  path = new NodePath(hub, parent);
4573
4368
  if (targetNode) paths.set(targetNode, path);
4574
4369
  }
4575
- path.setup(parentPath, container, listKey, key);
4370
+ setup.call(path, parentPath, container, listKey, key);
4576
4371
  return path;
4577
4372
  }
4578
4373
  getScope(scope) {
@@ -4646,7 +4441,6 @@ const methods = {
4646
4441
  isDescendant: isDescendant,
4647
4442
  inType: inType,
4648
4443
  getTypeAnnotation: getTypeAnnotation,
4649
- _getTypeAnnotation: _getTypeAnnotation,
4650
4444
  isBaseType: isBaseType,
4651
4445
  couldBeBaseType: couldBeBaseType,
4652
4446
  baseTypeStrictlyMatches: baseTypeStrictlyMatches,
@@ -4654,7 +4448,6 @@ const methods = {
4654
4448
  replaceWithMultiple: replaceWithMultiple,
4655
4449
  replaceWithSourceString: replaceWithSourceString,
4656
4450
  replaceWith: replaceWith,
4657
- _replaceWith: _replaceWith,
4658
4451
  replaceExpressionWithStatements: replaceExpressionWithStatements,
4659
4452
  replaceInline: replaceInline,
4660
4453
  evaluateTruthy: evaluateTruthy,
@@ -4663,12 +4456,10 @@ const methods = {
4663
4456
  ensureBlock: ensureBlock,
4664
4457
  unwrapFunctionEnvironment: unwrapFunctionEnvironment,
4665
4458
  arrowFunctionToExpression: arrowFunctionToExpression,
4459
+ splitExportDeclaration: splitExportDeclaration,
4460
+ ensureFunctionName: ensureFunctionName,
4666
4461
  matchesPattern: matchesPattern,
4667
- has: has,
4668
4462
  isStatic: isStatic,
4669
- is: is,
4670
- isnt: isnt,
4671
- equals: equals,
4672
4463
  isNodeType: isNodeType,
4673
4464
  canHaveVariableDeclarationOrExpression: canHaveVariableDeclarationOrExpression,
4674
4465
  canSwapBetweenExpressionAndStatement: canSwapBetweenExpressionAndStatement,
@@ -4679,46 +4470,21 @@ const methods = {
4679
4470
  willIMaybeExecuteBefore: willIMaybeExecuteBefore,
4680
4471
  _guessExecutionStatusRelativeTo: _guessExecutionStatusRelativeTo,
4681
4472
  resolve: resolve,
4682
- _resolve: _resolve,
4683
4473
  isConstantExpression: isConstantExpression,
4684
4474
  isInStrictMode: isInStrictMode,
4685
- call: call,
4686
- _call: _call,
4687
4475
  isDenylisted: isDenylisted,
4688
- isBlacklisted: isDenylisted,
4689
4476
  visit: visit,
4690
4477
  skip: skip,
4691
4478
  skipKey: skipKey,
4692
4479
  stop: stop,
4693
- setScope: setScope,
4694
4480
  setContext: setContext,
4695
- resync: resync,
4696
- _resyncParent: _resyncParent,
4697
- _resyncKey: _resyncKey,
4698
- _resyncList: _resyncList,
4699
- _resyncRemoved: _resyncRemoved,
4700
- popContext: popContext,
4701
- pushContext: pushContext,
4702
- setup: setup,
4703
- setKey: setKey,
4704
4481
  requeue: requeue,
4705
- _getQueueContexts: _getQueueContexts,
4482
+ requeueComputedKeyAndDecorators: requeueComputedKeyAndDecorators,
4706
4483
  remove: remove,
4707
- _removeFromScope: _removeFromScope,
4708
- _callRemovalHooks: _callRemovalHooks,
4709
- _remove: _remove,
4710
- _markRemoved: _markRemoved,
4711
- _assertUnremoved: _assertUnremoved,
4712
4484
  insertBefore: insertBefore,
4713
- _containerInsert: _containerInsert,
4714
- _containerInsertBefore: _containerInsertBefore,
4715
- _containerInsertAfter: _containerInsertAfter,
4716
4485
  insertAfter: insertAfter,
4717
- updateSiblingKeys: updateSiblingKeys,
4718
- _verifyNodeList: _verifyNodeList,
4719
4486
  unshiftContainer: unshiftContainer,
4720
4487
  pushContainer: pushContainer,
4721
- hoist: hoist,
4722
4488
  getOpposite: getOpposite,
4723
4489
  getCompletionRecords: getCompletionRecords,
4724
4490
  getSibling: getSibling,
@@ -4727,8 +4493,7 @@ const methods = {
4727
4493
  getAllNextSiblings: getAllNextSiblings,
4728
4494
  getAllPrevSiblings: getAllPrevSiblings,
4729
4495
  get: get,
4730
- _getKey: _getKey,
4731
- _getPattern: _getPattern,
4496
+ getAssignmentIdentifiers: getAssignmentIdentifiers,
4732
4497
  getBindingIdentifiers: getBindingIdentifiers,
4733
4498
  getOuterBindingIdentifiers: getOuterBindingIdentifiers,
4734
4499
  getBindingIdentifierPaths: getBindingIdentifierPaths,
@@ -4826,9 +4591,9 @@ class TraversalContext {
4826
4591
  for (; visitIndex < queue.length;) {
4827
4592
  const path = queue[visitIndex];
4828
4593
  visitIndex++;
4829
- path.resync();
4594
+ resync.call(path);
4830
4595
  if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
4831
- path.pushContext(this);
4596
+ pushContext.call(path, this);
4832
4597
  }
4833
4598
  if (path.key === null) continue;
4834
4599
  const {
@@ -4848,7 +4613,7 @@ class TraversalContext {
4848
4613
  }
4849
4614
  }
4850
4615
  for (let i = 0; i < visitIndex; i++) {
4851
- queue[i].popContext();
4616
+ popContext.call(queue[i]);
4852
4617
  }
4853
4618
  this.queue = null;
4854
4619
  return stop;
@@ -4884,6 +4649,205 @@ function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
4884
4649
  return false;
4885
4650
  }
4886
4651
 
4652
+ function call(key) {
4653
+ const opts = this.opts;
4654
+ this.debug(key);
4655
+ if (this.node) {
4656
+ if (_call.call(this, opts[key])) return true;
4657
+ }
4658
+ if (this.node) {
4659
+ return _call.call(this, opts[this.node.type]?.[key]);
4660
+ }
4661
+ return false;
4662
+ }
4663
+ function _call(fns) {
4664
+ if (!fns) return false;
4665
+ for (const fn of fns) {
4666
+ if (!fn) continue;
4667
+ const node = this.node;
4668
+ if (!node) return true;
4669
+ const ret = fn.call(this.state, this, this.state);
4670
+ if (ret && typeof ret === "object" && typeof ret.then === "function") {
4671
+ throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
4672
+ }
4673
+ if (ret) {
4674
+ throw new Error(`Unexpected return value from visitor method ${fn}`);
4675
+ }
4676
+ if (this.node !== node) return true;
4677
+ if (this._traverseFlags > 0) return true;
4678
+ }
4679
+ return false;
4680
+ }
4681
+ function isDenylisted() {
4682
+ const denylist = this.opts.denylist ?? this.opts.blacklist;
4683
+ return denylist?.includes(this.node.type);
4684
+ }
4685
+ function restoreContext(path, context) {
4686
+ if (path.context !== context) {
4687
+ path.context = context;
4688
+ path.state = context.state;
4689
+ path.opts = context.opts;
4690
+ }
4691
+ }
4692
+ function visit() {
4693
+ if (!this.node) {
4694
+ return false;
4695
+ }
4696
+ if (this.isDenylisted()) {
4697
+ return false;
4698
+ }
4699
+ if (this.opts.shouldSkip?.(this)) {
4700
+ return false;
4701
+ }
4702
+ const currentContext = this.context;
4703
+ if (this.shouldSkip || call.call(this, "enter")) {
4704
+ this.debug("Skip...");
4705
+ return this.shouldStop;
4706
+ }
4707
+ restoreContext(this, currentContext);
4708
+ this.debug("Recursing into...");
4709
+ this.shouldStop = traverseNode(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
4710
+ restoreContext(this, currentContext);
4711
+ call.call(this, "exit");
4712
+ return this.shouldStop;
4713
+ }
4714
+ function skip() {
4715
+ this.shouldSkip = true;
4716
+ }
4717
+ function skipKey(key) {
4718
+ if (this.skipKeys == null) {
4719
+ this.skipKeys = {};
4720
+ }
4721
+ this.skipKeys[key] = true;
4722
+ }
4723
+ function stop() {
4724
+ this._traverseFlags |= SHOULD_SKIP | SHOULD_STOP;
4725
+ }
4726
+ function setScope() {
4727
+ if (this.opts?.noScope) return;
4728
+ let path = this.parentPath;
4729
+ if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {
4730
+ path = path.parentPath;
4731
+ }
4732
+ let target;
4733
+ while (path && !target) {
4734
+ if (path.opts?.noScope) return;
4735
+ target = path.scope;
4736
+ path = path.parentPath;
4737
+ }
4738
+ this.scope = this.getScope(target);
4739
+ this.scope?.init();
4740
+ }
4741
+ function setContext(context) {
4742
+ if (this.skipKeys != null) {
4743
+ this.skipKeys = {};
4744
+ }
4745
+ this._traverseFlags = 0;
4746
+ if (context) {
4747
+ this.context = context;
4748
+ this.state = context.state;
4749
+ this.opts = context.opts;
4750
+ }
4751
+ setScope.call(this);
4752
+ return this;
4753
+ }
4754
+ function resync() {
4755
+ if (this.removed) return;
4756
+ _resyncParent.call(this);
4757
+ _resyncList.call(this);
4758
+ _resyncKey.call(this);
4759
+ }
4760
+ function _resyncParent() {
4761
+ if (this.parentPath) {
4762
+ this.parent = this.parentPath.node;
4763
+ }
4764
+ }
4765
+ function _resyncKey() {
4766
+ if (!this.container) return;
4767
+ if (this.node === this.container[this.key]) {
4768
+ return;
4769
+ }
4770
+ if (Array.isArray(this.container)) {
4771
+ for (let i = 0; i < this.container.length; i++) {
4772
+ if (this.container[i] === this.node) {
4773
+ setKey.call(this, i);
4774
+ return;
4775
+ }
4776
+ }
4777
+ } else {
4778
+ for (const key of Object.keys(this.container)) {
4779
+ if (this.container[key] === this.node) {
4780
+ setKey.call(this, key);
4781
+ return;
4782
+ }
4783
+ }
4784
+ }
4785
+ this.key = null;
4786
+ }
4787
+ function _resyncList() {
4788
+ if (!this.parent || !this.inList) return;
4789
+ const newContainer = this.parent[this.listKey];
4790
+ if (this.container === newContainer) return;
4791
+ this.container = newContainer || null;
4792
+ }
4793
+ function popContext() {
4794
+ this.contexts.pop();
4795
+ if (this.contexts.length > 0) {
4796
+ this.setContext(this.contexts[this.contexts.length - 1]);
4797
+ } else {
4798
+ this.setContext(undefined);
4799
+ }
4800
+ }
4801
+ function pushContext(context) {
4802
+ this.contexts.push(context);
4803
+ this.setContext(context);
4804
+ }
4805
+ function setup(parentPath, container, listKey, key) {
4806
+ this.listKey = listKey;
4807
+ this.container = container;
4808
+ this.parentPath = parentPath || this.parentPath;
4809
+ setKey.call(this, key);
4810
+ }
4811
+ function setKey(key) {
4812
+ this.key = key;
4813
+ this.node = this.container[this.key];
4814
+ this.type = this.node?.type;
4815
+ }
4816
+ function requeue(pathToQueue = this) {
4817
+ if (pathToQueue.removed) return;
4818
+ {
4819
+ pathToQueue.shouldSkip = false;
4820
+ }
4821
+ const contexts = this.contexts;
4822
+ for (const context of contexts) {
4823
+ context.maybeQueue(pathToQueue);
4824
+ }
4825
+ }
4826
+ function requeueComputedKeyAndDecorators() {
4827
+ const {
4828
+ context,
4829
+ node
4830
+ } = this;
4831
+ if (!_t.isPrivate(node) && node.computed) {
4832
+ context.maybeQueue(this.get("key"));
4833
+ }
4834
+ if (node.decorators) {
4835
+ for (const decorator of this.get("decorators")) {
4836
+ context.maybeQueue(decorator);
4837
+ }
4838
+ }
4839
+ }
4840
+ function _getQueueContexts() {
4841
+ let path = this;
4842
+ let contexts = this.contexts;
4843
+ while (!contexts.length) {
4844
+ path = path.parentPath;
4845
+ if (!path) break;
4846
+ contexts = path.contexts;
4847
+ }
4848
+ return contexts;
4849
+ }
4850
+
4887
4851
  class Hub {
4888
4852
  getCode() {}
4889
4853
  getScope() {}