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

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