@babel/traverse 8.0.0-alpha.9 → 8.0.0-beta.1

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 { createRequire } from 'module';
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-beta.1"}`);
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;
@@ -563,7 +559,7 @@ class Binding {
563
559
  this.scope = scope;
564
560
  this.path = path;
565
561
  this.kind = kind;
566
- if ((kind === "var" || kind === "hoisted") && isDeclaredInLoop(path)) {
562
+ if ((kind === "var" || kind === "hoisted") && isInitInLoop(path)) {
567
563
  this.reassign(path);
568
564
  }
569
565
  this.clearValue();
@@ -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;
@@ -607,24 +603,66 @@ class Binding {
607
603
  this.referenced = !!this.references;
608
604
  }
609
605
  }
610
- function isDeclaredInLoop(path) {
606
+ function isInitInLoop(path) {
607
+ const isFunctionDeclarationOrHasInit = !path.isVariableDeclarator() || path.node.init;
611
608
  for (let {
612
609
  parentPath,
613
610
  key
614
- } = path; parentPath; ({
611
+ } = path; parentPath; {
615
612
  parentPath,
616
613
  key
617
- } = parentPath)) {
614
+ } = parentPath) {
618
615
  if (parentPath.isFunctionParent()) return false;
619
- if (parentPath.isWhile() || parentPath.isForXStatement() || parentPath.isForStatement() && key === "body") {
616
+ if (key === "left" && parentPath.isForXStatement() || isFunctionDeclarationOrHasInit && key === "body" && parentPath.isLoop()) {
620
617
  return true;
621
618
  }
622
619
  }
623
620
  return false;
624
621
  }
625
622
 
623
+ let pathsCache = new WeakMap();
624
+ let scope = new WeakMap();
625
+ function clear() {
626
+ clearPath();
627
+ clearScope();
628
+ }
629
+ function clearPath() {
630
+ pathsCache = new WeakMap();
631
+ }
632
+ function clearScope() {
633
+ scope = new WeakMap();
634
+ }
635
+ function getCachedPaths(path) {
636
+ const {
637
+ parent,
638
+ parentPath
639
+ } = path;
640
+ return parentPath ? parentPath._store : pathsCache.get(parent);
641
+ }
642
+ function getOrCreateCachedPaths(node, parentPath) {
643
+ if (parentPath) {
644
+ return parentPath._store ||= new Map();
645
+ }
646
+ let paths = pathsCache.get(node);
647
+ if (!paths) pathsCache.set(node, paths = new Map());
648
+ return paths;
649
+ }
650
+
651
+ var cache = /*#__PURE__*/Object.freeze({
652
+ __proto__: null,
653
+ clear: clear,
654
+ clearPath: clearPath,
655
+ clearScope: clearScope,
656
+ getCachedPaths: getCachedPaths,
657
+ getOrCreateCachedPaths: getOrCreateCachedPaths,
658
+ get path () { return pathsCache; },
659
+ get scope () { return scope; }
660
+ });
661
+
662
+ const globalsBuiltinLower = createRequire(import.meta.url)("@babel/helper-globals/data/builtin-lower.json"),
663
+ globalsBuiltinUpper = createRequire(import.meta.url)("@babel/helper-globals/data/builtin-upper.json");
626
664
  const {
627
- NOT_LOCAL_BINDING,
665
+ assignmentExpression: assignmentExpression$3,
628
666
  callExpression: callExpression$3,
629
667
  cloneNode: cloneNode$3,
630
668
  getBindingIdentifiers: getBindingIdentifiers$3,
@@ -656,6 +694,7 @@ const {
656
694
  isThisExpression,
657
695
  isUnaryExpression,
658
696
  isVariableDeclaration: isVariableDeclaration$1,
697
+ expressionStatement: expressionStatement$3,
659
698
  matchesPattern: matchesPattern$1,
660
699
  memberExpression: memberExpression$1,
661
700
  numericLiteral: numericLiteral$2,
@@ -669,7 +708,8 @@ const {
669
708
  isMetaProperty,
670
709
  isPrivateName,
671
710
  isExportDeclaration,
672
- buildUndefinedNode: buildUndefinedNode$1
711
+ buildUndefinedNode: buildUndefinedNode$1,
712
+ sequenceExpression: sequenceExpression$2
673
713
  } = _t;
674
714
  function gatherNodeParts(node, parts) {
675
715
  switch (node?.type) {
@@ -728,6 +768,7 @@ function gatherNodeParts(node, parts) {
728
768
  parts.push("super");
729
769
  break;
730
770
  case "Import":
771
+ case "ImportExpression":
731
772
  parts.push("import");
732
773
  break;
733
774
  case "DoExpression":
@@ -785,6 +826,14 @@ function gatherNodeParts(node, parts) {
785
826
  break;
786
827
  }
787
828
  }
829
+ function resetScope(scope) {
830
+ if (scope.path.type === "Program") {
831
+ scope.referencesSet = new Set();
832
+ scope.uidsSet = new Set();
833
+ }
834
+ scope.bindings = Object.create(null);
835
+ scope.globals = Object.create(null);
836
+ }
788
837
  const collectorVisitor = {
789
838
  ForStatement(path) {
790
839
  const declar = path.get("init");
@@ -807,7 +856,15 @@ const collectorVisitor = {
807
856
  const parent = path.scope.getBlockParent();
808
857
  parent.registerDeclaration(path);
809
858
  },
859
+ TSImportEqualsDeclaration(path) {
860
+ const parent = path.scope.getBlockParent();
861
+ parent.registerDeclaration(path);
862
+ },
810
863
  ReferencedIdentifier(path, state) {
864
+ if (_t.isTSQualifiedName(path.parent) && path.parent.right === path.node) {
865
+ return;
866
+ }
867
+ if (path.parentPath.isTSImportEqualsDeclaration()) return;
811
868
  state.references.push(path);
812
869
  },
813
870
  ForXStatement(path, state) {
@@ -878,30 +935,31 @@ const collectorVisitor = {
878
935
  for (const param of params) {
879
936
  path.scope.registerBinding("param", param);
880
937
  }
881
- if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
938
+ if (path.isFunctionExpression() && path.node.id) {
882
939
  path.scope.registerBinding("local", path.get("id"), path);
883
940
  }
884
941
  },
885
942
  ClassExpression(path) {
886
- if (path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
887
- path.scope.registerBinding("local", path);
943
+ if (path.node.id) {
944
+ path.scope.registerBinding("local", path.get("id"), path);
888
945
  }
889
946
  },
890
947
  TSTypeAnnotation(path) {
891
948
  path.skip();
892
949
  }
893
950
  };
951
+ let scopeVisitor;
894
952
  let uid = 0;
895
953
  class Scope {
896
954
  uid;
897
955
  path;
898
956
  block;
899
- labels;
900
957
  inited;
958
+ labels;
901
959
  bindings;
902
- references;
960
+ referencesSet;
903
961
  globals;
904
- uids;
962
+ uidsSet;
905
963
  data;
906
964
  crawling;
907
965
  constructor(path) {
@@ -919,7 +977,7 @@ class Scope {
919
977
  this.labels = new Map();
920
978
  this.inited = false;
921
979
  }
922
- static globals = Object.keys(globals.builtin);
980
+ static globals = [...globalsBuiltinLower, ...globalsBuiltinUpper];
923
981
  static contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
924
982
  get parent() {
925
983
  let parent,
@@ -932,14 +990,11 @@ class Scope {
932
990
  } while (path && !parent);
933
991
  return parent?.scope;
934
992
  }
935
- get parentBlock() {
936
- return this.path.parent;
937
- }
938
- get hub() {
939
- return this.path.hub;
993
+ get references() {
994
+ throw new Error("Scope#references is not available in Babel 8. Use Scope#referencesSet instead.");
940
995
  }
941
- traverse(node, opts, state) {
942
- traverse(node, opts, this, state, this.path);
996
+ get uids() {
997
+ throw new Error("Scope#uids is not available in Babel 8. Use Scope#uidsSet instead.");
943
998
  }
944
999
  generateDeclaredUidIdentifier(name) {
945
1000
  const id = this.generateUidIdentifier(name);
@@ -952,23 +1007,21 @@ class Scope {
952
1007
  return identifier$3(this.generateUid(name));
953
1008
  }
954
1009
  generateUid(name = "temp") {
955
- name = toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
1010
+ name = toIdentifier(name).replace(/^_+/, "").replace(/\d+$/g, "");
956
1011
  let uid;
957
- let i = 1;
1012
+ let i = 0;
958
1013
  do {
959
- uid = this._generateUid(name, i);
1014
+ uid = `_${name}`;
1015
+ if (i >= 11) uid += i - 1;else if (i >= 9) uid += i - 9;else if (i >= 1) uid += i + 1;
960
1016
  i++;
961
1017
  } while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
962
1018
  const program = this.getProgramParent();
963
- program.references[uid] = true;
964
- program.uids[uid] = true;
1019
+ {
1020
+ program.referencesSet.add(uid);
1021
+ program.uidsSet.add(uid);
1022
+ }
965
1023
  return uid;
966
1024
  }
967
- _generateUid(name, i) {
968
- let id = name;
969
- if (i > 1) id += i;
970
- return `_${id}`;
971
- }
972
1025
  generateUidBasedOnNode(node, defaultName) {
973
1026
  const parts = [];
974
1027
  gatherNodeParts(node, parts);
@@ -1012,7 +1065,7 @@ class Scope {
1012
1065
  if (local.kind === "local") return;
1013
1066
  const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const";
1014
1067
  if (duplicate) {
1015
- throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
1068
+ throw this.path.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
1016
1069
  }
1017
1070
  }
1018
1071
  rename(oldName, newName) {
@@ -1025,12 +1078,6 @@ class Scope {
1025
1078
  }
1026
1079
  }
1027
1080
  }
1028
- _renameFromMap(map, oldName, newName, value) {
1029
- if (map[oldName]) {
1030
- map[newName] = value;
1031
- map[oldName] = null;
1032
- }
1033
- }
1034
1081
  dump() {
1035
1082
  const sep = "-".repeat(60);
1036
1083
  console.log(sep);
@@ -1049,37 +1096,6 @@ class Scope {
1049
1096
  } while (scope = scope.parent);
1050
1097
  console.log(sep);
1051
1098
  }
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
1099
  hasLabel(name) {
1084
1100
  return !!this.getLabel(name);
1085
1101
  }
@@ -1125,7 +1141,7 @@ class Scope {
1125
1141
  return buildUndefinedNode$1();
1126
1142
  }
1127
1143
  registerConstantViolation(path) {
1128
- const ids = path.getBindingIdentifiers();
1144
+ const ids = path.getAssignmentIdentifiers();
1129
1145
  for (const name of Object.keys(ids)) {
1130
1146
  this.getBinding(name)?.reassign(path);
1131
1147
  }
@@ -1142,7 +1158,9 @@ class Scope {
1142
1158
  const parent = this.getProgramParent();
1143
1159
  const ids = path.getOuterBindingIdentifiers(true);
1144
1160
  for (const name of Object.keys(ids)) {
1145
- parent.references[name] = true;
1161
+ {
1162
+ parent.referencesSet.add(name);
1163
+ }
1146
1164
  for (const id of ids[name]) {
1147
1165
  const local = this.getOwnBinding(name);
1148
1166
  if (local) {
@@ -1150,7 +1168,7 @@ class Scope {
1150
1168
  this.checkBlockScopedCollisions(local, kind, name, id);
1151
1169
  }
1152
1170
  if (local) {
1153
- this.registerConstantViolation(bindingPath);
1171
+ local.reassign(bindingPath);
1154
1172
  } else {
1155
1173
  this.bindings[name] = new Binding({
1156
1174
  identifier: id,
@@ -1166,11 +1184,9 @@ class Scope {
1166
1184
  this.globals[node.name] = node;
1167
1185
  }
1168
1186
  hasUid(name) {
1169
- let scope = this;
1170
- do {
1171
- if (scope.uids[name]) return true;
1172
- } while (scope = scope.parent);
1173
- return false;
1187
+ {
1188
+ return this.getProgramParent().uidsSet.has(name);
1189
+ }
1174
1190
  }
1175
1191
  hasGlobal(name) {
1176
1192
  let scope = this;
@@ -1180,7 +1196,9 @@ class Scope {
1180
1196
  return false;
1181
1197
  }
1182
1198
  hasReference(name) {
1183
- return !!this.getProgramParent().references[name];
1199
+ {
1200
+ return this.getProgramParent().referencesSet.has(name);
1201
+ }
1184
1202
  }
1185
1203
  isPure(node, constantsOnly) {
1186
1204
  if (isIdentifier$5(node)) {
@@ -1280,34 +1298,42 @@ class Scope {
1280
1298
  }
1281
1299
  crawl() {
1282
1300
  const path = this.path;
1283
- this.references = Object.create(null);
1284
- this.bindings = Object.create(null);
1285
- this.globals = Object.create(null);
1286
- this.uids = Object.create(null);
1301
+ resetScope(this);
1287
1302
  this.data = Object.create(null);
1288
- const programParent = this.getProgramParent();
1289
- if (programParent.crawling) return;
1303
+ let scope = this;
1304
+ do {
1305
+ if (scope.crawling) return;
1306
+ if (scope.path.isProgram()) {
1307
+ break;
1308
+ }
1309
+ } while (scope = scope.parent);
1310
+ const programParent = scope;
1290
1311
  const state = {
1291
1312
  references: [],
1292
1313
  constantViolations: [],
1293
1314
  assignments: []
1294
1315
  };
1295
1316
  this.crawling = true;
1296
- if (path.type !== "Program" && isExplodedVisitor(collectorVisitor)) {
1297
- for (const visit of collectorVisitor.enter) {
1317
+ scopeVisitor ||= traverse.visitors.merge([{
1318
+ Scope(path) {
1319
+ resetScope(path.scope);
1320
+ }
1321
+ }, collectorVisitor]);
1322
+ if (path.type !== "Program") {
1323
+ for (const visit of scopeVisitor.enter) {
1298
1324
  visit.call(state, path, state);
1299
1325
  }
1300
- const typeVisitors = collectorVisitor[path.type];
1326
+ const typeVisitors = scopeVisitor[path.type];
1301
1327
  if (typeVisitors) {
1302
1328
  for (const visit of typeVisitors.enter) {
1303
1329
  visit.call(state, path, state);
1304
1330
  }
1305
1331
  }
1306
1332
  }
1307
- path.traverse(collectorVisitor, state);
1333
+ path.traverse(scopeVisitor, state);
1308
1334
  this.crawling = false;
1309
1335
  for (const path of state.assignments) {
1310
- const ids = path.getBindingIdentifiers();
1336
+ const ids = path.getAssignmentIdentifiers();
1311
1337
  for (const name of Object.keys(ids)) {
1312
1338
  if (path.scope.getBinding(name)) continue;
1313
1339
  programParent.addGlobal(ids[name]);
@@ -1415,20 +1441,6 @@ class Scope {
1415
1441
  } while (scope);
1416
1442
  return ids;
1417
1443
  }
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
1444
  bindingIdentifierEquals(name, node) {
1433
1445
  return this.getBindingIdentifier(name) === node;
1434
1446
  }
@@ -1462,16 +1474,28 @@ class Scope {
1462
1474
  }
1463
1475
  hasBinding(name, opts) {
1464
1476
  if (!name) return false;
1465
- if (this.hasOwnBinding(name)) return true;
1466
- {
1467
- if (typeof opts === "boolean") opts = {
1468
- noGlobals: opts
1469
- };
1477
+ let noGlobals;
1478
+ let noUids;
1479
+ let upToScope;
1480
+ if (typeof opts === "object") {
1481
+ noGlobals = opts.noGlobals;
1482
+ noUids = opts.noUids;
1483
+ upToScope = opts.upToScope;
1484
+ } else if (typeof opts === "boolean") {
1485
+ noGlobals = opts;
1470
1486
  }
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;
1487
+ let scope = this;
1488
+ do {
1489
+ if (upToScope === scope) {
1490
+ break;
1491
+ }
1492
+ if (scope.hasOwnBinding(name)) {
1493
+ return true;
1494
+ }
1495
+ } while (scope = scope.parent);
1496
+ if (!noUids && this.hasUid(name)) return true;
1497
+ if (!noGlobals && Scope.globals.includes(name)) return true;
1498
+ if (!noGlobals && Scope.contextVariables.includes(name)) return true;
1475
1499
  return false;
1476
1500
  }
1477
1501
  parentHasBinding(name, opts) {
@@ -1490,12 +1514,57 @@ class Scope {
1490
1514
  }
1491
1515
  removeBinding(name) {
1492
1516
  this.getBinding(name)?.scope.removeOwnBinding(name);
1493
- let scope = this;
1494
- do {
1495
- if (scope.uids[name]) {
1496
- scope.uids[name] = false;
1517
+ {
1518
+ this.getProgramParent().uidsSet.delete(name);
1519
+ }
1520
+ }
1521
+ hoistVariables(emit = id => this.push({
1522
+ id
1523
+ })) {
1524
+ this.crawl();
1525
+ const seen = new Set();
1526
+ for (const name of Object.keys(this.bindings)) {
1527
+ const binding = this.bindings[name];
1528
+ if (!binding) continue;
1529
+ const {
1530
+ path
1531
+ } = binding;
1532
+ if (!path.isVariableDeclarator()) continue;
1533
+ const {
1534
+ parent,
1535
+ parentPath
1536
+ } = path;
1537
+ if (parent.kind !== "var" || seen.has(parent)) continue;
1538
+ seen.add(path.parent);
1539
+ let firstId;
1540
+ const init = [];
1541
+ for (const decl of parent.declarations) {
1542
+ firstId ??= decl.id;
1543
+ if (decl.init) {
1544
+ init.push(assignmentExpression$3("=", decl.id, decl.init));
1545
+ }
1546
+ const ids = Object.keys(getBindingIdentifiers$3(decl, false, true, true));
1547
+ for (const name of ids) {
1548
+ emit(identifier$3(name), decl.init != null);
1549
+ }
1497
1550
  }
1498
- } while (scope = scope.parent);
1551
+ if (parentPath.parentPath.isFor({
1552
+ left: parent
1553
+ })) {
1554
+ parentPath.replaceWith(firstId);
1555
+ } else if (init.length === 0) {
1556
+ parentPath.remove();
1557
+ } else {
1558
+ const expr = init.length === 1 ? init[0] : sequenceExpression$2(init);
1559
+ if (parentPath.parentPath.isForStatement({
1560
+ init: parent
1561
+ })) {
1562
+ parentPath.replaceWith(expr);
1563
+ } else {
1564
+ parentPath.replaceWith(expressionStatement$3(expr));
1565
+ }
1566
+ }
1567
+ }
1499
1568
  }
1500
1569
  }
1501
1570
 
@@ -1615,9 +1684,7 @@ function isDescendant(maybeAncestor) {
1615
1684
  function inType(...candidateTypes) {
1616
1685
  let path = this;
1617
1686
  while (path) {
1618
- for (const type of candidateTypes) {
1619
- if (path.node.type === type) return true;
1620
- }
1687
+ if (candidateTypes.includes(path.node.type)) return true;
1621
1688
  path = path.parentPath;
1622
1689
  }
1623
1690
  return false;
@@ -1670,7 +1737,7 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
1670
1737
  const testType = getConditionalAnnotation(binding, path, name);
1671
1738
  if (testType) {
1672
1739
  const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
1673
- constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0);
1740
+ constantViolations = constantViolations.filter(path => !testConstantViolations.includes(path));
1674
1741
  types.push(testType.typeAnnotation);
1675
1742
  }
1676
1743
  if (constantViolations.length) {
@@ -1712,7 +1779,7 @@ function inferAnnotationFromBinaryExpression(name, path) {
1712
1779
  if (operator === "===") {
1713
1780
  return target.getTypeAnnotation();
1714
1781
  }
1715
- if (BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
1782
+ if (BOOLEAN_NUMBER_BINARY_OPERATORS.includes(operator)) {
1716
1783
  return numberTypeAnnotation$1();
1717
1784
  }
1718
1785
  return;
@@ -1830,19 +1897,19 @@ function UnaryExpression(node) {
1830
1897
  const operator = node.operator;
1831
1898
  if (operator === "void") {
1832
1899
  return voidTypeAnnotation$1();
1833
- } else if (NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
1900
+ } else if (NUMBER_UNARY_OPERATORS.includes(operator)) {
1834
1901
  return numberTypeAnnotation();
1835
- } else if (STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
1902
+ } else if (STRING_UNARY_OPERATORS.includes(operator)) {
1836
1903
  return stringTypeAnnotation$1();
1837
- } else if (BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
1904
+ } else if (BOOLEAN_UNARY_OPERATORS.includes(operator)) {
1838
1905
  return booleanTypeAnnotation();
1839
1906
  }
1840
1907
  }
1841
1908
  function BinaryExpression(node) {
1842
1909
  const operator = node.operator;
1843
- if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
1910
+ if (NUMBER_BINARY_OPERATORS.includes(operator)) {
1844
1911
  return numberTypeAnnotation();
1845
- } else if (BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
1912
+ } else if (BOOLEAN_BINARY_OPERATORS.includes(operator)) {
1846
1913
  return booleanTypeAnnotation();
1847
1914
  } else if (operator === "+") {
1848
1915
  const right = this.get("right");
@@ -2011,7 +2078,7 @@ function getTypeAnnotation() {
2011
2078
  if (type != null) {
2012
2079
  return type;
2013
2080
  }
2014
- type = this._getTypeAnnotation() || anyTypeAnnotation();
2081
+ type = _getTypeAnnotation.call(this) || anyTypeAnnotation();
2015
2082
  if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {
2016
2083
  type = type.typeAnnotation;
2017
2084
  }
@@ -2118,42 +2185,323 @@ function isGenericType(genericName) {
2118
2185
  });
2119
2186
  }
2120
2187
 
2188
+ const hooks = [function (self, parent) {
2189
+ 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();
2190
+ if (removeParent) {
2191
+ parent.remove();
2192
+ return true;
2193
+ }
2194
+ }, function (self, parent) {
2195
+ if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
2196
+ parent.replaceWith(parent.node.expressions[0]);
2197
+ return true;
2198
+ }
2199
+ }, function (self, parent) {
2200
+ if (parent.isBinary()) {
2201
+ if (self.key === "left") {
2202
+ parent.replaceWith(parent.node.right);
2203
+ } else {
2204
+ parent.replaceWith(parent.node.left);
2205
+ }
2206
+ return true;
2207
+ }
2208
+ }, function (self, parent) {
2209
+ if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
2210
+ self.replaceWith({
2211
+ type: "BlockStatement",
2212
+ body: []
2213
+ });
2214
+ return true;
2215
+ }
2216
+ }];
2217
+
2218
+ const {
2219
+ getBindingIdentifiers: getBindingIdentifiers$2
2220
+ } = _t;
2221
+ function remove() {
2222
+ _assertUnremoved.call(this);
2223
+ resync.call(this);
2224
+ if (_callRemovalHooks.call(this)) {
2225
+ _markRemoved.call(this);
2226
+ return;
2227
+ }
2228
+ if (!this.opts?.noScope) {
2229
+ _removeFromScope.call(this);
2230
+ }
2231
+ this.shareCommentsWithSiblings();
2232
+ _remove.call(this);
2233
+ _markRemoved.call(this);
2234
+ }
2235
+ function _removeFromScope() {
2236
+ const bindings = getBindingIdentifiers$2(this.node, false, false, true);
2237
+ Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
2238
+ }
2239
+ function _callRemovalHooks() {
2240
+ if (this.parentPath) {
2241
+ for (const fn of hooks) {
2242
+ if (fn(this, this.parentPath)) return true;
2243
+ }
2244
+ }
2245
+ }
2246
+ function _remove() {
2247
+ if (Array.isArray(this.container)) {
2248
+ this.container.splice(this.key, 1);
2249
+ updateSiblingKeys.call(this, this.key, -1);
2250
+ } else {
2251
+ _replaceWith.call(this, null);
2252
+ }
2253
+ }
2254
+ function _markRemoved() {
2255
+ this._traverseFlags |= SHOULD_SKIP | REMOVED;
2256
+ if (this.parent) {
2257
+ getCachedPaths(this)?.delete(this.node);
2258
+ }
2259
+ this.node = null;
2260
+ }
2261
+ function _assertUnremoved() {
2262
+ if (this.removed) {
2263
+ throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
2264
+ }
2265
+ }
2266
+
2121
2267
  const {
2122
- FUNCTION_TYPES,
2123
2268
  arrowFunctionExpression: arrowFunctionExpression$2,
2269
+ assertExpression,
2124
2270
  assignmentExpression: assignmentExpression$2,
2125
- awaitExpression,
2126
2271
  blockStatement: blockStatement$2,
2127
- buildUndefinedNode,
2128
2272
  callExpression: callExpression$2,
2129
2273
  cloneNode: cloneNode$2,
2130
- conditionalExpression: conditionalExpression$1,
2131
2274
  expressionStatement: expressionStatement$2,
2132
- getBindingIdentifiers: getBindingIdentifiers$2,
2133
- identifier: identifier$1,
2134
- inheritLeadingComments,
2135
- inheritTrailingComments,
2136
- inheritsComments,
2137
- isBlockStatement: isBlockStatement$1,
2138
- isEmptyStatement,
2275
+ isAssignmentExpression,
2276
+ isCallExpression,
2277
+ isExportNamedDeclaration,
2139
2278
  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
2150
- } = _t;
2279
+ isIdentifier: isIdentifier$2,
2280
+ isSequenceExpression,
2281
+ isSuper,
2282
+ thisExpression: thisExpression$1
2283
+ } = _t;
2284
+ function insertBefore(nodes_) {
2285
+ _assertUnremoved.call(this);
2286
+ const nodes = _verifyNodeList.call(this, nodes_);
2287
+ const {
2288
+ parentPath,
2289
+ parent
2290
+ } = this;
2291
+ if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
2292
+ return parentPath.insertBefore(nodes);
2293
+ } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
2294
+ if (this.node) nodes.push(this.node);
2295
+ return this.replaceExpressionWithStatements(nodes);
2296
+ } else if (Array.isArray(this.container)) {
2297
+ return _containerInsertBefore.call(this, nodes);
2298
+ } else if (this.isStatementOrBlock()) {
2299
+ const node = this.node;
2300
+ const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
2301
+ this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
2302
+ return this.unshiftContainer("body", nodes);
2303
+ } else {
2304
+ 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?");
2305
+ }
2306
+ }
2307
+ function _containerInsert(from, nodes) {
2308
+ updateSiblingKeys.call(this, from, nodes.length);
2309
+ const paths = [];
2310
+ this.container.splice(from, 0, ...nodes);
2311
+ for (let i = 0; i < nodes.length; i++) {
2312
+ const to = from + i;
2313
+ const path = this.getSibling(to);
2314
+ paths.push(path);
2315
+ if (this.context?.queue) {
2316
+ pushContext.call(path, this.context);
2317
+ }
2318
+ }
2319
+ const contexts = _getQueueContexts.call(this);
2320
+ for (const path of paths) {
2321
+ setScope.call(path);
2322
+ path.debug("Inserted.");
2323
+ for (const context of contexts) {
2324
+ context.maybeQueue(path, true);
2325
+ }
2326
+ }
2327
+ return paths;
2328
+ }
2329
+ function _containerInsertBefore(nodes) {
2330
+ return _containerInsert.call(this, this.key, nodes);
2331
+ }
2332
+ function _containerInsertAfter(nodes) {
2333
+ return _containerInsert.call(this, this.key + 1, nodes);
2334
+ }
2335
+ const last = arr => arr[arr.length - 1];
2336
+ function isHiddenInSequenceExpression(path) {
2337
+ return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
2338
+ }
2339
+ function isAlmostConstantAssignment(node, scope) {
2340
+ if (!isAssignmentExpression(node) || !isIdentifier$2(node.left)) {
2341
+ return false;
2342
+ }
2343
+ const blockScope = scope.getBlockParent();
2344
+ return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
2345
+ }
2346
+ function insertAfter(nodes_) {
2347
+ _assertUnremoved.call(this);
2348
+ if (this.isSequenceExpression()) {
2349
+ return last(this.get("expressions")).insertAfter(nodes_);
2350
+ }
2351
+ const nodes = _verifyNodeList.call(this, nodes_);
2352
+ const {
2353
+ parentPath,
2354
+ parent
2355
+ } = this;
2356
+ if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
2357
+ return parentPath.insertAfter(nodes.map(node => {
2358
+ return isExpression$2(node) ? expressionStatement$2(node) : node;
2359
+ }));
2360
+ } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
2361
+ const self = this;
2362
+ if (self.node) {
2363
+ const node = self.node;
2364
+ let {
2365
+ scope
2366
+ } = this;
2367
+ if (scope.path.isPattern()) {
2368
+ assertExpression(node);
2369
+ self.replaceWith(callExpression$2(arrowFunctionExpression$2([], node), []));
2370
+ self.get("callee.body").insertAfter(nodes);
2371
+ return [self];
2372
+ }
2373
+ if (isHiddenInSequenceExpression(self)) {
2374
+ nodes.unshift(node);
2375
+ } else if (isCallExpression(node) && isSuper(node.callee)) {
2376
+ nodes.unshift(node);
2377
+ nodes.push(thisExpression$1());
2378
+ } else if (isAlmostConstantAssignment(node, scope)) {
2379
+ nodes.unshift(node);
2380
+ nodes.push(cloneNode$2(node.left));
2381
+ } else if (scope.isPure(node, true)) {
2382
+ nodes.push(node);
2383
+ } else {
2384
+ if (parentPath.isMethod({
2385
+ computed: true,
2386
+ key: node
2387
+ })) {
2388
+ scope = scope.parent;
2389
+ }
2390
+ const temp = scope.generateDeclaredUidIdentifier();
2391
+ nodes.unshift(expressionStatement$2(assignmentExpression$2("=", cloneNode$2(temp), node)));
2392
+ nodes.push(expressionStatement$2(cloneNode$2(temp)));
2393
+ }
2394
+ }
2395
+ return this.replaceExpressionWithStatements(nodes);
2396
+ } else if (Array.isArray(this.container)) {
2397
+ return _containerInsertAfter.call(this, nodes);
2398
+ } else if (this.isStatementOrBlock()) {
2399
+ const node = this.node;
2400
+ const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
2401
+ this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
2402
+ return this.pushContainer("body", nodes);
2403
+ } else {
2404
+ 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?");
2405
+ }
2406
+ }
2407
+ function updateSiblingKeys(fromIndex, incrementBy) {
2408
+ if (!this.parent) return;
2409
+ const paths = getCachedPaths(this);
2410
+ if (!paths) return;
2411
+ for (const [, path] of paths) {
2412
+ if (typeof path.key === "number" && path.container === this.container && path.key >= fromIndex) {
2413
+ path.key += incrementBy;
2414
+ }
2415
+ }
2416
+ }
2417
+ function _verifyNodeList(nodes) {
2418
+ if (!nodes) {
2419
+ return [];
2420
+ }
2421
+ if (!Array.isArray(nodes)) {
2422
+ nodes = [nodes];
2423
+ }
2424
+ for (let i = 0; i < nodes.length; i++) {
2425
+ const node = nodes[i];
2426
+ let msg;
2427
+ if (!node) {
2428
+ msg = "has falsy node";
2429
+ } else if (typeof node !== "object") {
2430
+ msg = "contains a non-object node";
2431
+ } else if (!node.type) {
2432
+ msg = "without a type";
2433
+ } else if (node instanceof NodePath_Final) {
2434
+ msg = "has a NodePath when it expected a raw object";
2435
+ }
2436
+ if (msg) {
2437
+ const type = Array.isArray(node) ? "array" : typeof node;
2438
+ throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
2439
+ }
2440
+ }
2441
+ return nodes;
2442
+ }
2443
+ function unshiftContainer(listKey, nodes) {
2444
+ _assertUnremoved.call(this);
2445
+ nodes = _verifyNodeList.call(this, nodes);
2446
+ const path = NodePath_Final.get({
2447
+ parentPath: this,
2448
+ parent: this.node,
2449
+ container: this.node[listKey],
2450
+ listKey,
2451
+ key: 0
2452
+ }).setContext(this.context);
2453
+ return _containerInsertBefore.call(path, nodes);
2454
+ }
2455
+ function pushContainer(listKey, nodes) {
2456
+ _assertUnremoved.call(this);
2457
+ const verifiedNodes = _verifyNodeList.call(this, nodes);
2458
+ const container = this.node[listKey];
2459
+ const path = NodePath_Final.get({
2460
+ parentPath: this,
2461
+ parent: this.node,
2462
+ container: container,
2463
+ listKey,
2464
+ key: container.length
2465
+ }).setContext(this.context);
2466
+ return path.replaceWithMultiple(verifiedNodes);
2467
+ }
2468
+
2469
+ const {
2470
+ FUNCTION_TYPES,
2471
+ arrowFunctionExpression: arrowFunctionExpression$1,
2472
+ assignmentExpression: assignmentExpression$1,
2473
+ awaitExpression,
2474
+ blockStatement: blockStatement$1,
2475
+ buildUndefinedNode,
2476
+ callExpression: callExpression$1,
2477
+ cloneNode: cloneNode$1,
2478
+ conditionalExpression: conditionalExpression$1,
2479
+ expressionStatement: expressionStatement$1,
2480
+ getBindingIdentifiers: getBindingIdentifiers$1,
2481
+ identifier: identifier$1,
2482
+ inheritLeadingComments,
2483
+ inheritTrailingComments,
2484
+ inheritsComments,
2485
+ isBlockStatement: isBlockStatement$1,
2486
+ isEmptyStatement,
2487
+ isExpression: isExpression$1,
2488
+ isExpressionStatement,
2489
+ isIfStatement,
2490
+ isProgram,
2491
+ isStatement,
2492
+ isVariableDeclaration,
2493
+ removeComments,
2494
+ returnStatement: returnStatement$1,
2495
+ sequenceExpression: sequenceExpression$1,
2496
+ validate: validate$1,
2497
+ yieldExpression
2498
+ } = _t;
2151
2499
  function replaceWithMultiple(nodes) {
2152
- this.resync();
2153
- nodes = this._verifyNodeList(nodes);
2500
+ resync.call(this);
2501
+ nodes = _verifyNodeList.call(this, nodes);
2154
2502
  inheritLeadingComments(nodes[0], this.node);
2155
2503
  inheritTrailingComments(nodes[nodes.length - 1], this.node);
2156
- getCachedPaths(this.hub, this.parent)?.delete(this.node);
2504
+ getCachedPaths(this)?.delete(this.node);
2157
2505
  this.node = this.container[this.key] = null;
2158
2506
  const paths = this.insertAfter(nodes);
2159
2507
  if (this.node) {
@@ -2164,7 +2512,7 @@ function replaceWithMultiple(nodes) {
2164
2512
  return paths;
2165
2513
  }
2166
2514
  function replaceWithSourceString(replacement) {
2167
- this.resync();
2515
+ resync.call(this);
2168
2516
  let ast;
2169
2517
  try {
2170
2518
  replacement = `(${replacement})`;
@@ -2187,7 +2535,7 @@ function replaceWithSourceString(replacement) {
2187
2535
  return this.replaceWith(expressionAST);
2188
2536
  }
2189
2537
  function replaceWith(replacementPath) {
2190
- this.resync();
2538
+ resync.call(this);
2191
2539
  if (this.removed) {
2192
2540
  throw new Error("You can't replace this node, we've already removed it");
2193
2541
  }
@@ -2208,9 +2556,9 @@ function replaceWith(replacementPath) {
2208
2556
  throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
2209
2557
  }
2210
2558
  let nodePath = "";
2211
- if (this.isNodeType("Statement") && isExpression$2(replacement)) {
2559
+ if (this.isNodeType("Statement") && isExpression$1(replacement)) {
2212
2560
  if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
2213
- replacement = expressionStatement$2(replacement);
2561
+ replacement = expressionStatement$1(replacement);
2214
2562
  nodePath = "expression";
2215
2563
  }
2216
2564
  }
@@ -2224,9 +2572,9 @@ function replaceWith(replacementPath) {
2224
2572
  inheritsComments(replacement, oldNode);
2225
2573
  removeComments(oldNode);
2226
2574
  }
2227
- this._replaceWith(replacement);
2575
+ _replaceWith.call(this, replacement);
2228
2576
  this.type = replacement.type;
2229
- this.setScope();
2577
+ setScope.call(this);
2230
2578
  this.requeue();
2231
2579
  return [nodePath ? this.get(nodePath) : this];
2232
2580
  }
@@ -2240,11 +2588,11 @@ function _replaceWith(node) {
2240
2588
  validate$1(this.parent, this.key, node);
2241
2589
  }
2242
2590
  this.debug(`Replace with ${node?.type}`);
2243
- getCachedPaths(this.hub, this.parent)?.set(node, this).delete(this.node);
2591
+ getCachedPaths(this)?.set(node, this).delete(this.node);
2244
2592
  this.node = this.container[this.key] = node;
2245
2593
  }
2246
2594
  function replaceExpressionWithStatements(nodes) {
2247
- this.resync();
2595
+ resync.call(this);
2248
2596
  const declars = [];
2249
2597
  const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);
2250
2598
  if (nodesAsSingleExpression) {
@@ -2254,17 +2602,15 @@ function replaceExpressionWithStatements(nodes) {
2254
2602
  return this.replaceWith(nodesAsSingleExpression)[0].get("expressions");
2255
2603
  }
2256
2604
  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, []));
2605
+ const isParentAsync = functionParent?.node.async;
2606
+ const isParentGenerator = functionParent?.node.generator;
2607
+ const container = arrowFunctionExpression$1([], blockStatement$1(nodes));
2608
+ this.replaceWith(callExpression$1(container, []));
2261
2609
  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();
2610
+ callee.get("body").scope.hoistVariables(id => this.scope.push({
2611
+ id
2612
+ }));
2613
+ const completionRecords = callee.getCompletionRecords();
2268
2614
  for (const path of completionRecords) {
2269
2615
  if (!path.isExpressionStatement()) continue;
2270
2616
  const loop = path.findParent(path => path.isLoop());
@@ -2272,12 +2618,12 @@ function replaceExpressionWithStatements(nodes) {
2272
2618
  let uid = loop.getData("expressionReplacementReturnUid");
2273
2619
  if (!uid) {
2274
2620
  uid = callee.scope.generateDeclaredUidIdentifier("ret");
2275
- callee.get("body").pushContainer("body", returnStatement$1(cloneNode$2(uid)));
2621
+ callee.get("body").pushContainer("body", returnStatement$1(cloneNode$1(uid)));
2276
2622
  loop.setData("expressionReplacementReturnUid", uid);
2277
2623
  } else {
2278
2624
  uid = identifier$1(uid.name);
2279
2625
  }
2280
- path.get("expression").replaceWith(assignmentExpression$2("=", cloneNode$2(uid), path.node.expression));
2626
+ path.get("expression").replaceWith(assignmentExpression$1("=", cloneNode$1(uid), path.node.expression));
2281
2627
  } else {
2282
2628
  path.replaceWith(returnStatement$1(path.node.expression));
2283
2629
  }
@@ -2305,19 +2651,19 @@ function gatherSequenceExpressions(nodes, declars) {
2305
2651
  if (!isEmptyStatement(node)) {
2306
2652
  ensureLastUndefined = false;
2307
2653
  }
2308
- if (isExpression$2(node)) {
2654
+ if (isExpression$1(node)) {
2309
2655
  exprs.push(node);
2310
2656
  } else if (isExpressionStatement(node)) {
2311
2657
  exprs.push(node.expression);
2312
2658
  } else if (isVariableDeclaration(node)) {
2313
2659
  if (node.kind !== "var") return;
2314
2660
  for (const declar of node.declarations) {
2315
- const bindings = getBindingIdentifiers$2(declar);
2661
+ const bindings = getBindingIdentifiers$1(declar);
2316
2662
  for (const key of Object.keys(bindings)) {
2317
- declars.push(cloneNode$2(bindings[key]));
2663
+ declars.push(cloneNode$1(bindings[key]));
2318
2664
  }
2319
2665
  if (declar.init) {
2320
- exprs.push(assignmentExpression$2("=", declar.id, declar.init));
2666
+ exprs.push(assignmentExpression$1("=", declar.id, declar.init));
2321
2667
  }
2322
2668
  }
2323
2669
  ensureLastUndefined = true;
@@ -2346,11 +2692,11 @@ function gatherSequenceExpressions(nodes, declars) {
2346
2692
  }
2347
2693
  }
2348
2694
  function replaceInline(nodes) {
2349
- this.resync();
2695
+ resync.call(this);
2350
2696
  if (Array.isArray(nodes)) {
2351
2697
  if (Array.isArray(this.container)) {
2352
- nodes = this._verifyNodeList(nodes);
2353
- const paths = this._containerInsertAfter(nodes);
2698
+ nodes = _verifyNodeList.call(this, nodes);
2699
+ const paths = _containerInsertAfter.call(this, nodes);
2354
2700
  this.remove();
2355
2701
  return paths;
2356
2702
  } else {
@@ -2477,6 +2823,22 @@ function _evaluate(path, state) {
2477
2823
  deopt(binding.path, state);
2478
2824
  return;
2479
2825
  }
2826
+ const bindingPathScope = binding.path.scope;
2827
+ if (binding.kind === "var" && bindingPathScope !== binding.scope) {
2828
+ let hasUnsafeBlock = !bindingPathScope.path.parentPath.isBlockStatement();
2829
+ for (let scope = bindingPathScope.parent; scope; scope = scope.parent) {
2830
+ if (scope === path.scope) {
2831
+ if (hasUnsafeBlock) {
2832
+ deopt(binding.path, state);
2833
+ return;
2834
+ }
2835
+ break;
2836
+ }
2837
+ if (scope.path.parentPath?.isBlockStatement()) {
2838
+ hasUnsafeBlock = true;
2839
+ }
2840
+ }
2841
+ }
2480
2842
  if (binding.hasValue) {
2481
2843
  return binding.value;
2482
2844
  }
@@ -2493,9 +2855,13 @@ function _evaluate(path, state) {
2493
2855
  if (resolved === path) {
2494
2856
  deopt(path, state);
2495
2857
  return;
2496
- } else {
2497
- return evaluateCached(resolved, state);
2498
2858
  }
2859
+ const value = evaluateCached(resolved, state);
2860
+ if (typeof value === "object" && value !== null && binding.references > 1) {
2861
+ deopt(resolved, state);
2862
+ return;
2863
+ }
2864
+ return value;
2499
2865
  }
2500
2866
  if (path.isUnaryExpression({
2501
2867
  prefix: true
@@ -2701,15 +3067,15 @@ function evaluate() {
2701
3067
  }
2702
3068
 
2703
3069
  const {
2704
- arrowFunctionExpression: arrowFunctionExpression$1,
2705
- assignmentExpression: assignmentExpression$1,
3070
+ arrowFunctionExpression,
3071
+ assignmentExpression,
2706
3072
  binaryExpression,
2707
- blockStatement: blockStatement$1,
2708
- callExpression: callExpression$1,
3073
+ blockStatement,
3074
+ callExpression,
2709
3075
  conditionalExpression,
2710
- expressionStatement: expressionStatement$1,
3076
+ expressionStatement,
2711
3077
  identifier,
2712
- isIdentifier: isIdentifier$2,
3078
+ isIdentifier: isIdentifier$1,
2713
3079
  jsxIdentifier,
2714
3080
  logicalExpression,
2715
3081
  LOGICAL_OPERATORS,
@@ -2723,9 +3089,20 @@ const {
2723
3089
  spreadElement,
2724
3090
  stringLiteral,
2725
3091
  super: _super,
2726
- thisExpression: thisExpression$1,
3092
+ thisExpression,
2727
3093
  toExpression,
2728
- unaryExpression: unaryExpression$1
3094
+ unaryExpression: unaryExpression$1,
3095
+ toBindingIdentifierName,
3096
+ isFunction,
3097
+ isAssignmentPattern,
3098
+ isRestElement,
3099
+ getFunctionName,
3100
+ cloneNode,
3101
+ variableDeclaration,
3102
+ variableDeclarator,
3103
+ exportNamedDeclaration,
3104
+ exportSpecifier,
3105
+ inherits
2729
3106
  } = _t;
2730
3107
  function toComputedKey() {
2731
3108
  let key;
@@ -2737,7 +3114,7 @@ function toComputedKey() {
2737
3114
  throw new ReferenceError("todo");
2738
3115
  }
2739
3116
  if (!this.node.computed) {
2740
- if (isIdentifier$2(key)) key = stringLiteral(key.name);
3117
+ if (isIdentifier$1(key)) key = stringLiteral(key.name);
2741
3118
  }
2742
3119
  return key;
2743
3120
  }
@@ -2768,12 +3145,12 @@ function ensureBlock() {
2768
3145
  statements.push(returnStatement(body.node));
2769
3146
  } else {
2770
3147
  key = "expression";
2771
- statements.push(expressionStatement$1(body.node));
3148
+ statements.push(expressionStatement(body.node));
2772
3149
  }
2773
3150
  }
2774
- this.node.body = blockStatement$1(statements);
3151
+ this.node.body = blockStatement(statements);
2775
3152
  const parentPath = this.get(stringPath);
2776
- body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
3153
+ setup.call(body, parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
2777
3154
  return this.node;
2778
3155
  }
2779
3156
  function unwrapFunctionEnvironment() {
@@ -2793,10 +3170,14 @@ function arrowFunctionToExpression({
2793
3170
  if (!this.isArrowFunctionExpression()) {
2794
3171
  throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
2795
3172
  }
3173
+ let self = this;
3174
+ if (!noNewArrows) {
3175
+ self = self.ensureFunctionName(false) ?? self;
3176
+ }
2796
3177
  const {
2797
3178
  thisBinding,
2798
3179
  fnPath: fn
2799
- } = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow, allowInsertArrowWithRest);
3180
+ } = hoistFunctionEnvironment(self, noNewArrows, allowInsertArrow, allowInsertArrowWithRest);
2800
3181
  fn.ensureBlock();
2801
3182
  setType(fn, "FunctionExpression");
2802
3183
  if (!noNewArrows) {
@@ -2807,20 +3188,20 @@ function arrowFunctionToExpression({
2807
3188
  init: objectExpression([])
2808
3189
  });
2809
3190
  }
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()]));
3191
+ fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
3192
+ fn.replaceWith(callExpression(memberExpression(fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
2812
3193
  return fn.get("callee.object");
2813
3194
  }
2814
3195
  return fn;
2815
3196
  }
2816
- const getSuperCallsVisitor = merge([{
3197
+ const getSuperCallsVisitor = environmentVisitor({
2817
3198
  CallExpression(child, {
2818
3199
  allSuperCalls
2819
3200
  }) {
2820
3201
  if (!child.get("callee").isSuper()) return;
2821
3202
  allSuperCalls.push(child);
2822
3203
  }
2823
- }, environmentVisitor]);
3204
+ });
2824
3205
  function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true, allowInsertArrowWithRest = true) {
2825
3206
  let arrowParent;
2826
3207
  let thisEnvFn = fnPath.findParent(p => {
@@ -2841,7 +3222,7 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
2841
3222
  if (arrowParent) {
2842
3223
  thisEnvFn = arrowParent;
2843
3224
  } else if (allowInsertArrow) {
2844
- fnPath.replaceWith(callExpression$1(arrowFunctionExpression$1([], toExpression(fnPath.node)), []));
3225
+ fnPath.replaceWith(callExpression(arrowFunctionExpression([], toExpression(fnPath.node)), []));
2845
3226
  thisEnvFn = fnPath.get("callee");
2846
3227
  fnPath = thisEnvFn.get("body");
2847
3228
  } else {
@@ -2922,15 +3303,15 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
2922
3303
  const value = superParentPath.node.right;
2923
3304
  args.push(value);
2924
3305
  }
2925
- const call = callExpression$1(identifier(superBinding), args);
3306
+ const call = callExpression(identifier(superBinding), args);
2926
3307
  if (isCall) {
2927
- superParentPath.unshiftContainer("arguments", thisExpression$1());
3308
+ superParentPath.unshiftContainer("arguments", thisExpression());
2928
3309
  superProp.replaceWith(memberExpression(call, identifier("call")));
2929
3310
  thisPaths.push(superParentPath.get("arguments.0"));
2930
3311
  } else if (isAssignment) {
2931
3312
  superParentPath.replaceWith(call);
2932
3313
  } else if (isTaggedTemplate) {
2933
- superProp.replaceWith(callExpression$1(memberExpression(call, identifier("bind"), false), [thisExpression$1()]));
3314
+ superProp.replaceWith(callExpression(memberExpression(call, identifier("bind"), false), [thisExpression()]));
2934
3315
  thisPaths.push(superProp.get("arguments.0"));
2935
3316
  } else {
2936
3317
  superProp.replaceWith(call);
@@ -2967,7 +3348,7 @@ function standardizeSuperProperty(superProp) {
2967
3348
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
2968
3349
  const object = superProp.node.object;
2969
3350
  const property = superProp.node.property;
2970
- assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression$1("=", tmp, property), true));
3351
+ assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression("=", tmp, property), true));
2971
3352
  assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(tmp.name), true), value));
2972
3353
  } else {
2973
3354
  const object = superProp.node.object;
@@ -2985,7 +3366,7 @@ function standardizeSuperProperty(superProp) {
2985
3366
  const updateExpr = superProp.parentPath;
2986
3367
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
2987
3368
  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)))];
3369
+ 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
3370
  if (!superProp.parentPath.node.prefix) {
2990
3371
  parts.push(identifier(tmp.name));
2991
3372
  }
@@ -2997,7 +3378,7 @@ function standardizeSuperProperty(superProp) {
2997
3378
  return [superProp];
2998
3379
  function rightExpression(op, left, right) {
2999
3380
  if (op === "=") {
3000
- return assignmentExpression$1("=", left, right);
3381
+ return assignmentExpression("=", left, right);
3001
3382
  } else {
3002
3383
  return binaryExpression(op, left, right);
3003
3384
  }
@@ -3006,7 +3387,7 @@ function standardizeSuperProperty(superProp) {
3006
3387
  function hasSuperClass(thisEnvFn) {
3007
3388
  return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass;
3008
3389
  }
3009
- const assignSuperThisVisitor = merge([{
3390
+ const assignSuperThisVisitor = environmentVisitor({
3010
3391
  CallExpression(child, {
3011
3392
  supers,
3012
3393
  thisBinding
@@ -3014,12 +3395,12 @@ const assignSuperThisVisitor = merge([{
3014
3395
  if (!child.get("callee").isSuper()) return;
3015
3396
  if (supers.has(child.node)) return;
3016
3397
  supers.add(child.node);
3017
- child.replaceWithMultiple([child.node, assignmentExpression$1("=", identifier(thisBinding), identifier("this"))]);
3398
+ child.replaceWithMultiple([child.node, assignmentExpression("=", identifier(thisBinding), identifier("this"))]);
3018
3399
  }
3019
- }, environmentVisitor]);
3400
+ });
3020
3401
  function getThisBinding(thisEnvFn, inConstructor) {
3021
3402
  return getBinding(thisEnvFn, "this", thisBinding => {
3022
- if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression$1();
3403
+ if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression();
3023
3404
  thisEnvFn.traverse(assignSuperThisVisitor, {
3024
3405
  supers: new WeakSet(),
3025
3406
  thisBinding
@@ -3029,7 +3410,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
3029
3410
  function getSuperBinding(thisEnvFn) {
3030
3411
  return getBinding(thisEnvFn, "supercall", () => {
3031
3412
  const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
3032
- return arrowFunctionExpression$1([restElement(argsBinding)], callExpression$1(_super(), [spreadElement(identifier(argsBinding.name))]));
3413
+ return arrowFunctionExpression([restElement(argsBinding)], callExpression(_super(), [spreadElement(identifier(argsBinding.name))]));
3033
3414
  });
3034
3415
  }
3035
3416
  function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
@@ -3047,9 +3428,9 @@ function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
3047
3428
  if (isAssignment) {
3048
3429
  const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
3049
3430
  argsList.push(valueIdent);
3050
- fnBody = assignmentExpression$1("=", fnBody, identifier(valueIdent.name));
3431
+ fnBody = assignmentExpression("=", fnBody, identifier(valueIdent.name));
3051
3432
  }
3052
- return arrowFunctionExpression$1(argsList, fnBody);
3433
+ return arrowFunctionExpression(argsList, fnBody);
3053
3434
  });
3054
3435
  }
3055
3436
  function getBinding(thisEnvFn, key, init) {
@@ -3066,7 +3447,7 @@ function getBinding(thisEnvFn, key, init) {
3066
3447
  }
3067
3448
  return data;
3068
3449
  }
3069
- const getScopeInformationVisitor = merge([{
3450
+ const getScopeInformationVisitor = environmentVisitor({
3070
3451
  ThisExpression(child, {
3071
3452
  thisPaths
3072
3453
  }) {
@@ -3124,7 +3505,7 @@ const getScopeInformationVisitor = merge([{
3124
3505
  })) return;
3125
3506
  newTargetPaths.push(child);
3126
3507
  }
3127
- }, environmentVisitor]);
3508
+ });
3128
3509
  function getScopeInformation(fnPath) {
3129
3510
  const thisPaths = [];
3130
3511
  const argumentsPaths = [];
@@ -3146,53 +3527,165 @@ function getScopeInformation(fnPath) {
3146
3527
  superCalls
3147
3528
  };
3148
3529
  }
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;
3530
+ function splitExportDeclaration() {
3531
+ if (!this.isExportDeclaration() || this.isExportAllDeclaration()) {
3532
+ throw new Error("Only default and named export declarations can be split.");
3533
+ }
3534
+ if (this.isExportNamedDeclaration() && this.get("specifiers").length > 0) {
3535
+ throw new Error("It doesn't make sense to split exported specifiers.");
3536
+ }
3537
+ const declaration = this.get("declaration");
3538
+ if (this.isExportDefaultDeclaration()) {
3539
+ const standaloneDeclaration = declaration.isFunctionDeclaration() || declaration.isClassDeclaration();
3540
+ const exportExpr = declaration.isFunctionExpression() || declaration.isClassExpression();
3541
+ const scope = declaration.isScope() ? declaration.scope.parent : declaration.scope;
3542
+ let id = declaration.node.id;
3543
+ let needBindingRegistration = false;
3544
+ if (!id) {
3545
+ needBindingRegistration = true;
3546
+ id = scope.generateUidIdentifier("default");
3547
+ if (standaloneDeclaration || exportExpr) {
3548
+ declaration.node.id = cloneNode(id);
3549
+ }
3550
+ } else if (exportExpr && scope.hasBinding(id.name)) {
3551
+ needBindingRegistration = true;
3552
+ id = scope.generateUidIdentifier(id.name);
3553
+ }
3554
+ const updatedDeclaration = standaloneDeclaration ? declaration.node : variableDeclaration("var", [variableDeclarator(cloneNode(id), declaration.node)]);
3555
+ const updatedExportDeclaration = exportNamedDeclaration(null, [exportSpecifier(cloneNode(id), identifier("default"))]);
3556
+ this.insertAfter(updatedExportDeclaration);
3557
+ this.replaceWith(updatedDeclaration);
3558
+ if (needBindingRegistration) {
3559
+ scope.registerDeclaration(this);
3560
+ }
3561
+ return this;
3562
+ } else if (this.get("specifiers").length > 0) {
3563
+ throw new Error("It doesn't make sense to split exported specifiers.");
3170
3564
  }
3565
+ const bindingIdentifiers = declaration.getOuterBindingIdentifiers();
3566
+ const specifiers = Object.keys(bindingIdentifiers).map(name => {
3567
+ return exportSpecifier(identifier(name), identifier(name));
3568
+ });
3569
+ const aliasDeclar = exportNamedDeclaration(null, specifiers);
3570
+ this.insertAfter(aliasDeclar);
3571
+ this.replaceWith(declaration.node);
3572
+ return this;
3171
3573
  }
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()) {
3190
- return false;
3191
- }
3192
- if (this.isExpression()) {
3574
+ const refersOuterBindingVisitor = {
3575
+ "ReferencedIdentifier|BindingIdentifier"(path, state) {
3576
+ if (path.node.name !== state.name) return;
3577
+ state.needsRename = true;
3578
+ path.stop();
3579
+ },
3580
+ Scope(path, state) {
3581
+ if (path.scope.hasOwnBinding(state.name)) {
3582
+ path.skip();
3583
+ }
3584
+ }
3585
+ };
3586
+ function ensureFunctionName(supportUnicodeId) {
3587
+ if (this.node.id) return this;
3588
+ const res = getFunctionName(this.node, this.parent);
3589
+ if (res == null) return this;
3590
+ let {
3591
+ name
3592
+ } = res;
3593
+ if (!supportUnicodeId && /[\uD800-\uDFFF]/.test(name)) {
3594
+ return null;
3595
+ }
3596
+ if (name.startsWith("get ") || name.startsWith("set ")) {
3597
+ return null;
3598
+ }
3599
+ name = toBindingIdentifierName(name.replace(/[/ ]/g, "_"));
3600
+ const id = identifier(name);
3601
+ inherits(id, res.originalNode);
3602
+ const state = {
3603
+ needsRename: false,
3604
+ name
3605
+ };
3606
+ const {
3607
+ scope
3608
+ } = this;
3609
+ const binding = scope.getOwnBinding(name);
3610
+ if (binding) {
3611
+ if (binding.kind === "param") {
3612
+ state.needsRename = true;
3613
+ }
3614
+ } else if (scope.parent.hasBinding(name) || scope.hasGlobal(name)) {
3615
+ this.traverse(refersOuterBindingVisitor, state);
3616
+ }
3617
+ if (!state.needsRename) {
3618
+ this.node.id = id;
3619
+ {
3620
+ scope.getProgramParent().referencesSet.add(id.name);
3621
+ }
3622
+ return this;
3623
+ }
3624
+ if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
3625
+ scope.rename(id.name);
3626
+ this.node.id = id;
3627
+ {
3628
+ scope.getProgramParent().referencesSet.add(id.name);
3629
+ }
3630
+ return this;
3631
+ }
3632
+ if (!isFunction(this.node)) return null;
3633
+ const key = scope.generateUidIdentifier(id.name);
3634
+ const params = [];
3635
+ for (let i = 0, len = getFunctionArity(this.node); i < len; i++) {
3636
+ params.push(scope.generateUidIdentifier("x"));
3637
+ }
3638
+ const call = template.expression.ast`
3639
+ (function (${key}) {
3640
+ function ${id}(${params}) {
3641
+ return ${cloneNode(key)}.apply(this, arguments);
3642
+ }
3643
+
3644
+ ${cloneNode(id)}.toString = function () {
3645
+ return ${cloneNode(key)}.toString();
3646
+ }
3647
+
3648
+ return ${cloneNode(id)};
3649
+ })(${toExpression(this.node)})
3650
+ `;
3651
+ return this.replaceWith(call)[0].get("arguments.0");
3652
+ }
3653
+ function getFunctionArity(node) {
3654
+ const count = node.params.findIndex(param => isAssignmentPattern(param) || isRestElement(param));
3655
+ return count === -1 ? node.params.length : count;
3656
+ }
3657
+
3658
+ const {
3659
+ STATEMENT_OR_BLOCK_KEYS,
3660
+ VISITOR_KEYS: VISITOR_KEYS$3,
3661
+ isBlockStatement,
3662
+ isExpression,
3663
+ isIdentifier,
3664
+ isLiteral,
3665
+ isStringLiteral,
3666
+ isType,
3667
+ matchesPattern: _matchesPattern
3668
+ } = _t;
3669
+ function matchesPattern(pattern, allowPartial) {
3670
+ return _matchesPattern(this.node, pattern, allowPartial);
3671
+ }
3672
+ function isStatic() {
3673
+ return this.scope.isStatic(this.node);
3674
+ }
3675
+ function isNodeType(type) {
3676
+ return isType(this.type, type);
3677
+ }
3678
+ function canHaveVariableDeclarationOrExpression() {
3679
+ return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
3680
+ }
3681
+ function canSwapBetweenExpressionAndStatement(replacement) {
3682
+ if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
3683
+ return false;
3684
+ }
3685
+ if (this.isExpression()) {
3193
3686
  return isBlockStatement(replacement);
3194
3687
  } else if (this.isBlockStatement()) {
3195
- return isExpression$1(replacement);
3688
+ return isExpression(replacement);
3196
3689
  }
3197
3690
  return false;
3198
3691
  }
@@ -3247,7 +3740,7 @@ function referencesImport(moduleSource, importName) {
3247
3740
  if (path.isImportNamespaceSpecifier() && importName === "*") {
3248
3741
  return true;
3249
3742
  }
3250
- if (path.isImportSpecifier() && isIdentifier$1(path.node.imported, {
3743
+ if (path.isImportSpecifier() && isIdentifier(path.node.imported, {
3251
3744
  name: importName
3252
3745
  })) {
3253
3746
  return true;
@@ -3321,8 +3814,8 @@ function _guessExecutionStatusRelativeToCached(base, target, cache) {
3321
3814
  target: target.getAncestry(),
3322
3815
  this: base.getAncestry()
3323
3816
  };
3324
- if (paths.target.indexOf(base) >= 0) return "after";
3325
- if (paths.this.indexOf(target) >= 0) return "before";
3817
+ if (paths.target.includes(base)) return "after";
3818
+ if (paths.this.includes(target)) return "before";
3326
3819
  let commonPath;
3327
3820
  const commonIndex = {
3328
3821
  target: 0,
@@ -3402,10 +3895,10 @@ function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, c
3402
3895
  return result;
3403
3896
  }
3404
3897
  function resolve(dangerous, resolved) {
3405
- return this._resolve(dangerous, resolved) || this;
3898
+ return _resolve.call(this, dangerous, resolved) || this;
3406
3899
  }
3407
3900
  function _resolve(dangerous, resolved) {
3408
- if (resolved && resolved.indexOf(this) >= 0) return;
3901
+ if (resolved?.includes(this)) return;
3409
3902
  resolved = resolved || [];
3410
3903
  resolved.push(this);
3411
3904
  if (this.isVariableDeclarator()) {
@@ -3508,651 +4001,17 @@ function isInStrictMode() {
3508
4001
  } else {
3509
4002
  return false;
3510
4003
  }
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?");
4088
- }
4089
- }
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;
4096
- }
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";
4117
- }
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}`);
4004
+ for (const directive of body.directives) {
4005
+ if (directive.value.value === "use strict") {
4006
+ return true;
4007
+ }
4121
4008
  }
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();
4009
+ });
4010
+ return !!strictParent;
4153
4011
  }
4154
4012
 
4155
4013
  const {
4014
+ getAssignmentIdentifiers: _getAssignmentIdentifiers,
4156
4015
  getBindingIdentifiers: _getBindingIdentifiers,
4157
4016
  getOuterBindingIdentifiers: _getOuterBindingIdentifiers,
4158
4017
  numericLiteral,
@@ -4250,12 +4109,16 @@ function getStatementListCompletion(paths, context) {
4250
4109
  completions.push(...lastNormalCompletions);
4251
4110
  if (lastNormalCompletions.some(c => c.path.isDeclaration())) {
4252
4111
  completions.push(...statementCompletions);
4253
- replaceBreakStatementInBreakCompletion(statementCompletions, true);
4112
+ if (!context.shouldPreserveBreak) {
4113
+ replaceBreakStatementInBreakCompletion(statementCompletions, true);
4114
+ }
4115
+ }
4116
+ if (!context.shouldPreserveBreak) {
4117
+ replaceBreakStatementInBreakCompletion(statementCompletions, false);
4254
4118
  }
4255
- replaceBreakStatementInBreakCompletion(statementCompletions, false);
4256
4119
  } else {
4257
4120
  completions.push(...statementCompletions);
4258
- if (!context.shouldPopulateBreak) {
4121
+ if (!context.shouldPopulateBreak && !context.shouldPreserveBreak) {
4259
4122
  replaceBreakStatementInBreakCompletion(statementCompletions, true);
4260
4123
  }
4261
4124
  }
@@ -4279,7 +4142,7 @@ function getStatementListCompletion(paths, context) {
4279
4142
  } else if (paths.length) {
4280
4143
  for (let i = paths.length - 1; i >= 0; i--) {
4281
4144
  const pathCompletions = _getCompletionRecords(paths[i], context);
4282
- if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration()) {
4145
+ if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration() && !pathCompletions[0].path.isEmptyStatement()) {
4283
4146
  completions.push(...pathCompletions);
4284
4147
  break;
4285
4148
  }
@@ -4309,7 +4172,8 @@ function _getCompletionRecords(path, context) {
4309
4172
  return getStatementListCompletion(path.get("consequent"), {
4310
4173
  canHaveBreak: true,
4311
4174
  shouldPopulateBreak: false,
4312
- inCaseClause: true
4175
+ inCaseClause: true,
4176
+ shouldPreserveBreak: context.shouldPreserveBreak
4313
4177
  });
4314
4178
  } else if (path.isBreakStatement()) {
4315
4179
  records.push(BreakCompletion(path));
@@ -4318,11 +4182,12 @@ function _getCompletionRecords(path, context) {
4318
4182
  }
4319
4183
  return records;
4320
4184
  }
4321
- function getCompletionRecords() {
4185
+ function getCompletionRecords(shouldPreserveBreak = false) {
4322
4186
  const records = _getCompletionRecords(this, {
4323
4187
  canHaveBreak: false,
4324
4188
  shouldPopulateBreak: false,
4325
- inCaseClause: false
4189
+ inCaseClause: false,
4190
+ shouldPreserveBreak
4326
4191
  });
4327
4192
  return records.map(r => r.path);
4328
4193
  }
@@ -4365,9 +4230,9 @@ function get(key, context = true) {
4365
4230
  if (context === true) context = this.context;
4366
4231
  const parts = key.split(".");
4367
4232
  if (parts.length === 1) {
4368
- return this._getKey(key, context);
4233
+ return _getKey.call(this, key, context);
4369
4234
  } else {
4370
- return this._getPattern(parts, context);
4235
+ return _getPattern.call(this, parts, context);
4371
4236
  }
4372
4237
  }
4373
4238
  function _getKey(key, context) {
@@ -4407,6 +4272,9 @@ function _getPattern(parts, context) {
4407
4272
  }
4408
4273
  return path;
4409
4274
  }
4275
+ function getAssignmentIdentifiers() {
4276
+ return _getAssignmentIdentifiers(this.node);
4277
+ }
4410
4278
  function getBindingIdentifiers(duplicates) {
4411
4279
  return _getBindingIdentifiers(this.node, duplicates);
4412
4280
  }
@@ -4551,6 +4419,7 @@ const NodePath_Final = class NodePath {
4551
4419
  key = null;
4552
4420
  node = null;
4553
4421
  type = null;
4422
+ _store = null;
4554
4423
  static get({
4555
4424
  hub,
4556
4425
  parentPath,
@@ -4566,13 +4435,13 @@ const NodePath_Final = class NodePath {
4566
4435
  throw new Error("To get a node path the parent needs to exist");
4567
4436
  }
4568
4437
  const targetNode = container[key];
4569
- const paths = getOrCreateCachedPaths(hub, parent);
4438
+ const paths = getOrCreateCachedPaths(parent, parentPath);
4570
4439
  let path = paths.get(targetNode);
4571
4440
  if (!path) {
4572
4441
  path = new NodePath(hub, parent);
4573
4442
  if (targetNode) paths.set(targetNode, path);
4574
4443
  }
4575
- path.setup(parentPath, container, listKey, key);
4444
+ setup.call(path, parentPath, container, listKey, key);
4576
4445
  return path;
4577
4446
  }
4578
4447
  getScope(scope) {
@@ -4646,7 +4515,6 @@ const methods = {
4646
4515
  isDescendant: isDescendant,
4647
4516
  inType: inType,
4648
4517
  getTypeAnnotation: getTypeAnnotation,
4649
- _getTypeAnnotation: _getTypeAnnotation,
4650
4518
  isBaseType: isBaseType,
4651
4519
  couldBeBaseType: couldBeBaseType,
4652
4520
  baseTypeStrictlyMatches: baseTypeStrictlyMatches,
@@ -4654,7 +4522,6 @@ const methods = {
4654
4522
  replaceWithMultiple: replaceWithMultiple,
4655
4523
  replaceWithSourceString: replaceWithSourceString,
4656
4524
  replaceWith: replaceWith,
4657
- _replaceWith: _replaceWith,
4658
4525
  replaceExpressionWithStatements: replaceExpressionWithStatements,
4659
4526
  replaceInline: replaceInline,
4660
4527
  evaluateTruthy: evaluateTruthy,
@@ -4663,12 +4530,10 @@ const methods = {
4663
4530
  ensureBlock: ensureBlock,
4664
4531
  unwrapFunctionEnvironment: unwrapFunctionEnvironment,
4665
4532
  arrowFunctionToExpression: arrowFunctionToExpression,
4533
+ splitExportDeclaration: splitExportDeclaration,
4534
+ ensureFunctionName: ensureFunctionName,
4666
4535
  matchesPattern: matchesPattern,
4667
- has: has,
4668
4536
  isStatic: isStatic,
4669
- is: is,
4670
- isnt: isnt,
4671
- equals: equals,
4672
4537
  isNodeType: isNodeType,
4673
4538
  canHaveVariableDeclarationOrExpression: canHaveVariableDeclarationOrExpression,
4674
4539
  canSwapBetweenExpressionAndStatement: canSwapBetweenExpressionAndStatement,
@@ -4679,46 +4544,21 @@ const methods = {
4679
4544
  willIMaybeExecuteBefore: willIMaybeExecuteBefore,
4680
4545
  _guessExecutionStatusRelativeTo: _guessExecutionStatusRelativeTo,
4681
4546
  resolve: resolve,
4682
- _resolve: _resolve,
4683
4547
  isConstantExpression: isConstantExpression,
4684
4548
  isInStrictMode: isInStrictMode,
4685
- call: call,
4686
- _call: _call,
4687
4549
  isDenylisted: isDenylisted,
4688
- isBlacklisted: isDenylisted,
4689
4550
  visit: visit,
4690
4551
  skip: skip,
4691
4552
  skipKey: skipKey,
4692
4553
  stop: stop,
4693
- setScope: setScope,
4694
4554
  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
4555
  requeue: requeue,
4705
- _getQueueContexts: _getQueueContexts,
4556
+ requeueComputedKeyAndDecorators: requeueComputedKeyAndDecorators,
4706
4557
  remove: remove,
4707
- _removeFromScope: _removeFromScope,
4708
- _callRemovalHooks: _callRemovalHooks,
4709
- _remove: _remove,
4710
- _markRemoved: _markRemoved,
4711
- _assertUnremoved: _assertUnremoved,
4712
4558
  insertBefore: insertBefore,
4713
- _containerInsert: _containerInsert,
4714
- _containerInsertBefore: _containerInsertBefore,
4715
- _containerInsertAfter: _containerInsertAfter,
4716
4559
  insertAfter: insertAfter,
4717
- updateSiblingKeys: updateSiblingKeys,
4718
- _verifyNodeList: _verifyNodeList,
4719
4560
  unshiftContainer: unshiftContainer,
4720
4561
  pushContainer: pushContainer,
4721
- hoist: hoist,
4722
4562
  getOpposite: getOpposite,
4723
4563
  getCompletionRecords: getCompletionRecords,
4724
4564
  getSibling: getSibling,
@@ -4727,8 +4567,7 @@ const methods = {
4727
4567
  getAllNextSiblings: getAllNextSiblings,
4728
4568
  getAllPrevSiblings: getAllPrevSiblings,
4729
4569
  get: get,
4730
- _getKey: _getKey,
4731
- _getPattern: _getPattern,
4570
+ getAssignmentIdentifiers: getAssignmentIdentifiers,
4732
4571
  getBindingIdentifiers: getBindingIdentifiers,
4733
4572
  getOuterBindingIdentifiers: getOuterBindingIdentifiers,
4734
4573
  getBindingIdentifierPaths: getBindingIdentifierPaths,
@@ -4826,9 +4665,9 @@ class TraversalContext {
4826
4665
  for (; visitIndex < queue.length;) {
4827
4666
  const path = queue[visitIndex];
4828
4667
  visitIndex++;
4829
- path.resync();
4668
+ resync.call(path);
4830
4669
  if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
4831
- path.pushContext(this);
4670
+ pushContext.call(path, this);
4832
4671
  }
4833
4672
  if (path.key === null) continue;
4834
4673
  const {
@@ -4848,7 +4687,7 @@ class TraversalContext {
4848
4687
  }
4849
4688
  }
4850
4689
  for (let i = 0; i < visitIndex; i++) {
4851
- queue[i].popContext();
4690
+ popContext.call(queue[i]);
4852
4691
  }
4853
4692
  this.queue = null;
4854
4693
  return stop;
@@ -4867,22 +4706,313 @@ class TraversalContext {
4867
4706
  const {
4868
4707
  VISITOR_KEYS: VISITOR_KEYS$1
4869
4708
  } = _t;
4870
- function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
4709
+ function _visitPaths(ctx, paths) {
4710
+ ctx.queue = paths;
4711
+ ctx.priorityQueue = [];
4712
+ const visited = new Set();
4713
+ let stop = false;
4714
+ let visitIndex = 0;
4715
+ for (; visitIndex < paths.length;) {
4716
+ const path = paths[visitIndex];
4717
+ visitIndex++;
4718
+ resync.call(path);
4719
+ if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== ctx) {
4720
+ pushContext.call(path, ctx);
4721
+ }
4722
+ if (path.key === null) continue;
4723
+ const {
4724
+ node
4725
+ } = path;
4726
+ if (visited.has(node)) continue;
4727
+ if (node) visited.add(node);
4728
+ if (_visit(ctx, path)) {
4729
+ stop = true;
4730
+ break;
4731
+ }
4732
+ if (ctx.priorityQueue.length) {
4733
+ stop = _visitPaths(ctx, ctx.priorityQueue);
4734
+ ctx.priorityQueue = [];
4735
+ ctx.queue = paths;
4736
+ if (stop) break;
4737
+ }
4738
+ }
4739
+ for (let i = 0; i < visitIndex; i++) {
4740
+ popContext.call(paths[i]);
4741
+ }
4742
+ ctx.queue = null;
4743
+ return stop;
4744
+ }
4745
+ function _visit(ctx, path) {
4746
+ const node = path.node;
4747
+ if (!node) {
4748
+ return false;
4749
+ }
4750
+ const opts = ctx.opts;
4751
+ const denylist = opts.denylist ?? opts.blacklist;
4752
+ if (denylist?.includes(node.type)) {
4753
+ return false;
4754
+ }
4755
+ if (opts.shouldSkip?.(path)) {
4756
+ return false;
4757
+ }
4758
+ if (path.shouldSkip) return path.shouldStop;
4759
+ if (_call.call(path, opts.enter)) return path.shouldStop;
4760
+ if (path.node) {
4761
+ if (_call.call(path, opts[node.type]?.enter)) return path.shouldStop;
4762
+ }
4763
+ path.shouldStop = _traverse(path.node, opts, path.scope, ctx.state, path, path.skipKeys);
4764
+ if (path.node) {
4765
+ if (_call.call(path, opts.exit)) return true;
4766
+ }
4767
+ if (path.node) {
4768
+ _call.call(path, opts[node.type]?.exit);
4769
+ }
4770
+ return path.shouldStop;
4771
+ }
4772
+ function _traverse(node, opts, scope, state, path, skipKeys, visitSelf) {
4871
4773
  const keys = VISITOR_KEYS$1[node.type];
4872
- if (!keys) return false;
4873
- const context = new TraversalContext(scope, opts, state, path);
4774
+ if (!keys?.length) return false;
4775
+ const ctx = new TraversalContext(scope, opts, state, path);
4874
4776
  if (visitSelf) {
4875
4777
  if (skipKeys?.[path.parentKey]) return false;
4876
- return context.visitQueue([path]);
4778
+ return _visitPaths(ctx, [path]);
4877
4779
  }
4878
4780
  for (const key of keys) {
4879
4781
  if (skipKeys?.[key]) continue;
4880
- if (context.visit(node, key)) {
4881
- return true;
4782
+ const prop = node[key];
4783
+ if (!prop) continue;
4784
+ if (Array.isArray(prop)) {
4785
+ if (!prop.length) continue;
4786
+ const paths = [];
4787
+ for (let i = 0; i < prop.length; i++) {
4788
+ const childPath = NodePath_Final.get({
4789
+ parentPath: path,
4790
+ parent: node,
4791
+ container: prop,
4792
+ key: i,
4793
+ listKey: key
4794
+ });
4795
+ paths.push(childPath);
4796
+ }
4797
+ if (_visitPaths(ctx, paths)) return true;
4798
+ } else {
4799
+ if (_visitPaths(ctx, [NodePath_Final.get({
4800
+ parentPath: path,
4801
+ parent: node,
4802
+ container: node,
4803
+ key,
4804
+ listKey: null
4805
+ })])) {
4806
+ return true;
4807
+ }
4882
4808
  }
4883
4809
  }
4884
4810
  return false;
4885
4811
  }
4812
+ function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
4813
+ {
4814
+ return _traverse(node, opts, scope, state, path, skipKeys, visitSelf);
4815
+ }
4816
+ }
4817
+
4818
+ function call(key) {
4819
+ const opts = this.opts;
4820
+ this.debug(key);
4821
+ if (this.node) {
4822
+ if (_call.call(this, opts[key])) return true;
4823
+ }
4824
+ if (this.node) {
4825
+ return _call.call(this, opts[this.node.type]?.[key]);
4826
+ }
4827
+ return false;
4828
+ }
4829
+ function _call(fns) {
4830
+ if (!fns) return false;
4831
+ for (const fn of fns) {
4832
+ if (!fn) continue;
4833
+ const node = this.node;
4834
+ if (!node) return true;
4835
+ const ret = fn.call(this.state, this, this.state);
4836
+ if (ret && typeof ret === "object" && typeof ret.then === "function") {
4837
+ 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.`);
4838
+ }
4839
+ if (ret) {
4840
+ throw new Error(`Unexpected return value from visitor method ${fn}`);
4841
+ }
4842
+ if (this.node !== node) return true;
4843
+ if (this._traverseFlags > 0) return true;
4844
+ }
4845
+ return false;
4846
+ }
4847
+ function isDenylisted() {
4848
+ const denylist = this.opts.denylist ?? this.opts.blacklist;
4849
+ return denylist?.includes(this.node.type);
4850
+ }
4851
+ function restoreContext(path, context) {
4852
+ if (path.context !== context) {
4853
+ path.context = context;
4854
+ path.state = context.state;
4855
+ path.opts = context.opts;
4856
+ }
4857
+ }
4858
+ function visit() {
4859
+ if (!this.node) {
4860
+ return false;
4861
+ }
4862
+ if (this.isDenylisted()) {
4863
+ return false;
4864
+ }
4865
+ if (this.opts.shouldSkip?.(this)) {
4866
+ return false;
4867
+ }
4868
+ const currentContext = this.context;
4869
+ if (this.shouldSkip || call.call(this, "enter")) {
4870
+ this.debug("Skip...");
4871
+ return this.shouldStop;
4872
+ }
4873
+ restoreContext(this, currentContext);
4874
+ this.debug("Recursing into...");
4875
+ this.shouldStop = traverseNode(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
4876
+ restoreContext(this, currentContext);
4877
+ call.call(this, "exit");
4878
+ return this.shouldStop;
4879
+ }
4880
+ function skip() {
4881
+ this.shouldSkip = true;
4882
+ }
4883
+ function skipKey(key) {
4884
+ if (this.skipKeys == null) {
4885
+ this.skipKeys = {};
4886
+ }
4887
+ this.skipKeys[key] = true;
4888
+ }
4889
+ function stop() {
4890
+ this._traverseFlags |= SHOULD_SKIP | SHOULD_STOP;
4891
+ }
4892
+ function setScope() {
4893
+ if (this.opts?.noScope) return;
4894
+ let path = this.parentPath;
4895
+ if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {
4896
+ path = path.parentPath;
4897
+ }
4898
+ let target;
4899
+ while (path && !target) {
4900
+ if (path.opts?.noScope) return;
4901
+ target = path.scope;
4902
+ path = path.parentPath;
4903
+ }
4904
+ this.scope = this.getScope(target);
4905
+ this.scope?.init();
4906
+ }
4907
+ function setContext(context) {
4908
+ if (this.skipKeys != null) {
4909
+ this.skipKeys = {};
4910
+ }
4911
+ this._traverseFlags = 0;
4912
+ if (context) {
4913
+ this.context = context;
4914
+ this.state = context.state;
4915
+ this.opts = context.opts;
4916
+ }
4917
+ setScope.call(this);
4918
+ return this;
4919
+ }
4920
+ function resync() {
4921
+ if (this.removed) return;
4922
+ _resyncParent.call(this);
4923
+ _resyncList.call(this);
4924
+ _resyncKey.call(this);
4925
+ }
4926
+ function _resyncParent() {
4927
+ if (this.parentPath) {
4928
+ this.parent = this.parentPath.node;
4929
+ }
4930
+ }
4931
+ function _resyncKey() {
4932
+ if (!this.container) return;
4933
+ if (this.node === this.container[this.key]) {
4934
+ return;
4935
+ }
4936
+ if (Array.isArray(this.container)) {
4937
+ for (let i = 0; i < this.container.length; i++) {
4938
+ if (this.container[i] === this.node) {
4939
+ setKey.call(this, i);
4940
+ return;
4941
+ }
4942
+ }
4943
+ } else {
4944
+ for (const key of Object.keys(this.container)) {
4945
+ if (this.container[key] === this.node) {
4946
+ setKey.call(this, key);
4947
+ return;
4948
+ }
4949
+ }
4950
+ }
4951
+ this.key = null;
4952
+ }
4953
+ function _resyncList() {
4954
+ if (!this.parent || !this.inList) return;
4955
+ const newContainer = this.parent[this.listKey];
4956
+ if (this.container === newContainer) return;
4957
+ this.container = newContainer || null;
4958
+ }
4959
+ function popContext() {
4960
+ this.contexts.pop();
4961
+ if (this.contexts.length > 0) {
4962
+ this.setContext(this.contexts[this.contexts.length - 1]);
4963
+ } else {
4964
+ this.setContext(undefined);
4965
+ }
4966
+ }
4967
+ function pushContext(context) {
4968
+ this.contexts.push(context);
4969
+ this.setContext(context);
4970
+ }
4971
+ function setup(parentPath, container, listKey, key) {
4972
+ this.listKey = listKey;
4973
+ this.container = container;
4974
+ this.parentPath = parentPath || this.parentPath;
4975
+ setKey.call(this, key);
4976
+ }
4977
+ function setKey(key) {
4978
+ this.key = key;
4979
+ this.node = this.container[this.key];
4980
+ this.type = this.node?.type;
4981
+ }
4982
+ function requeue(pathToQueue = this) {
4983
+ if (pathToQueue.removed) return;
4984
+ {
4985
+ pathToQueue.shouldSkip = false;
4986
+ }
4987
+ const contexts = this.contexts;
4988
+ for (const context of contexts) {
4989
+ context.maybeQueue(pathToQueue);
4990
+ }
4991
+ }
4992
+ function requeueComputedKeyAndDecorators() {
4993
+ const {
4994
+ context,
4995
+ node
4996
+ } = this;
4997
+ if (!_t.isPrivate(node) && node.computed) {
4998
+ context.maybeQueue(this.get("key"));
4999
+ }
5000
+ if (node.decorators) {
5001
+ for (const decorator of this.get("decorators")) {
5002
+ context.maybeQueue(decorator);
5003
+ }
5004
+ }
5005
+ }
5006
+ function _getQueueContexts() {
5007
+ let path = this;
5008
+ let contexts = this.contexts;
5009
+ while (!contexts.length) {
5010
+ path = path.parentPath;
5011
+ if (!path) break;
5012
+ contexts = path.contexts;
5013
+ }
5014
+ return contexts;
5015
+ }
4886
5016
 
4887
5017
  class Hub {
4888
5018
  getCode() {}
@@ -4933,25 +5063,17 @@ traverse.removeProperties = function (tree, opts) {
4933
5063
  traverseFast(tree, traverse.clearNode, opts);
4934
5064
  return tree;
4935
5065
  };
4936
- function hasDenylistedType(path, state) {
4937
- if (path.node.type === state.type) {
4938
- state.has = true;
4939
- path.stop();
4940
- }
4941
- }
4942
5066
  traverse.hasType = function (tree, type, denylistTypes) {
4943
5067
  if (denylistTypes?.includes(tree.type)) return false;
4944
5068
  if (tree.type === type) return true;
4945
- const state = {
4946
- has: false,
4947
- type: type
4948
- };
4949
- traverse(tree, {
4950
- noScope: true,
4951
- denylist: denylistTypes,
4952
- enter: hasDenylistedType
4953
- }, null, state);
4954
- return state.has;
5069
+ return traverseFast(tree, function (node) {
5070
+ if (denylistTypes?.includes(node.type)) {
5071
+ return traverseFast.skip;
5072
+ }
5073
+ if (node.type === type) {
5074
+ return traverseFast.stop;
5075
+ }
5076
+ });
4955
5077
  };
4956
5078
  traverse.cache = cache;
4957
5079