@babel/traverse 7.20.7 → 7.20.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @babel/traverse might be problematic. Click here for more details.
- package/lib/context.js +2 -14
- package/lib/context.js.map +1 -1
- package/lib/index.js +1 -4
- package/lib/index.js.map +1 -1
- package/lib/path/ancestry.js +0 -19
- package/lib/path/ancestry.js.map +1 -1
- package/lib/path/comments.js +0 -2
- package/lib/path/comments.js.map +1 -1
- package/lib/path/context.js +5 -21
- package/lib/path/context.js.map +1 -1
- package/lib/path/conversion.js +6 -30
- package/lib/path/conversion.js.map +1 -1
- package/lib/path/evaluation.js +14 -20
- package/lib/path/evaluation.js.map +1 -1
- package/lib/path/family.js +3 -9
- package/lib/path/family.js.map +1 -1
- package/lib/path/index.js +1 -6
- package/lib/path/index.js.map +1 -1
- package/lib/path/inference/index.js +1 -9
- package/lib/path/inference/index.js.map +1 -1
- package/lib/path/inference/inferer-reference.js +1 -13
- package/lib/path/inference/inferer-reference.js.map +1 -1
- package/lib/path/inference/inferers.js +2 -5
- package/lib/path/inference/inferers.js.map +1 -1
- package/lib/path/introspection.js +16 -62
- package/lib/path/introspection.js.map +1 -1
- package/lib/path/lib/hoister.js +1 -22
- package/lib/path/lib/hoister.js.map +1 -1
- package/lib/path/lib/removal-hooks.js +1 -7
- package/lib/path/lib/removal-hooks.js.map +1 -1
- package/lib/path/lib/virtual-types-validator.js +0 -2
- package/lib/path/lib/virtual-types-validator.js.map +1 -1
- package/lib/path/lib/virtual-types.js +0 -1
- package/lib/path/lib/virtual-types.js.map +1 -1
- package/lib/path/modification.js +12 -24
- package/lib/path/modification.js.map +1 -1
- package/lib/path/removal.js +0 -1
- package/lib/path/removal.js.map +1 -1
- package/lib/path/replacement.js +2 -16
- package/lib/path/replacement.js.map +1 -1
- package/lib/scope/binding.js +1 -6
- package/lib/scope/binding.js.map +1 -1
- package/lib/scope/index.js +5 -50
- package/lib/scope/index.js.map +1 -1
- package/lib/scope/lib/renamer.js +1 -6
- package/lib/scope/lib/renamer.js.map +1 -1
- package/lib/visitors.js +2 -23
- package/lib/visitors.js.map +1 -1
- package/package.json +1 -1
package/lib/scope/index.js
CHANGED
@@ -170,7 +170,6 @@ function gatherNodeParts(node, parts) {
|
|
170
170
|
break;
|
171
171
|
}
|
172
172
|
}
|
173
|
-
|
174
173
|
const collectorVisitor = {
|
175
174
|
ForStatement(path) {
|
176
175
|
const declar = path.get("init");
|
@@ -184,11 +183,8 @@ const collectorVisitor = {
|
|
184
183
|
},
|
185
184
|
Declaration(path) {
|
186
185
|
if (path.isBlockScoped()) return;
|
187
|
-
|
188
186
|
if (path.isImportDeclaration()) return;
|
189
|
-
|
190
187
|
if (path.isExportDeclaration()) return;
|
191
|
-
|
192
188
|
const parent = path.scope.getFunctionParent() || path.scope.getProgramParent();
|
193
189
|
parent.registerDeclaration(path);
|
194
190
|
},
|
@@ -203,8 +199,7 @@ const collectorVisitor = {
|
|
203
199
|
const left = path.get("left");
|
204
200
|
if (left.isPattern() || left.isIdentifier()) {
|
205
201
|
state.constantViolations.push(path);
|
206
|
-
}
|
207
|
-
else if (left.isVar()) {
|
202
|
+
} else if (left.isVar()) {
|
208
203
|
const {
|
209
204
|
scope
|
210
205
|
} = path;
|
@@ -254,7 +249,6 @@ const collectorVisitor = {
|
|
254
249
|
if (scope.path === path) scope = scope.parent;
|
255
250
|
const parent = scope.getBlockParent();
|
256
251
|
parent.registerDeclaration(path);
|
257
|
-
|
258
252
|
if (path.isClassDeclaration() && path.node.id) {
|
259
253
|
const id = path.node.id;
|
260
254
|
const name = id.name;
|
@@ -269,15 +263,12 @@ const collectorVisitor = {
|
|
269
263
|
for (const param of params) {
|
270
264
|
path.scope.registerBinding("param", param);
|
271
265
|
}
|
272
|
-
|
273
|
-
if (path.isFunctionExpression() && path.has("id") &&
|
274
|
-
!path.get("id").node[NOT_LOCAL_BINDING]) {
|
266
|
+
if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
|
275
267
|
path.scope.registerBinding("local", path.get("id"), path);
|
276
268
|
}
|
277
269
|
},
|
278
270
|
ClassExpression(path) {
|
279
|
-
if (path.has("id") &&
|
280
|
-
!path.get("id").node[NOT_LOCAL_BINDING]) {
|
271
|
+
if (path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
|
281
272
|
path.scope.registerBinding("local", path);
|
282
273
|
}
|
283
274
|
}
|
@@ -310,7 +301,6 @@ class Scope {
|
|
310
301
|
this.labels = new Map();
|
311
302
|
this.inited = false;
|
312
303
|
}
|
313
|
-
|
314
304
|
get parent() {
|
315
305
|
var _parent;
|
316
306
|
let parent,
|
@@ -332,7 +322,6 @@ class Scope {
|
|
332
322
|
traverse(node, opts, state) {
|
333
323
|
(0, _index.default)(node, opts, this, state, this.path);
|
334
324
|
}
|
335
|
-
|
336
325
|
generateDeclaredUidIdentifier(name) {
|
337
326
|
const id = this.generateUidIdentifier(name);
|
338
327
|
this.push({
|
@@ -340,11 +329,9 @@ class Scope {
|
|
340
329
|
});
|
341
330
|
return cloneNode(id);
|
342
331
|
}
|
343
|
-
|
344
332
|
generateUidIdentifier(name) {
|
345
333
|
return identifier(this.generateUid(name));
|
346
334
|
}
|
347
|
-
|
348
335
|
generateUid(name = "temp") {
|
349
336
|
name = toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
350
337
|
let uid;
|
@@ -358,7 +345,6 @@ class Scope {
|
|
358
345
|
program.uids[uid] = true;
|
359
346
|
return uid;
|
360
347
|
}
|
361
|
-
|
362
348
|
_generateUid(name, i) {
|
363
349
|
let id = name;
|
364
350
|
if (i > 1) id += i;
|
@@ -371,11 +357,9 @@ class Scope {
|
|
371
357
|
id = id.replace(/^_/, "") || defaultName || "ref";
|
372
358
|
return this.generateUid(id.slice(0, 20));
|
373
359
|
}
|
374
|
-
|
375
360
|
generateUidIdentifierBasedOnNode(node, defaultName) {
|
376
361
|
return identifier(this.generateUidBasedOnNode(node, defaultName));
|
377
362
|
}
|
378
|
-
|
379
363
|
isStatic(node) {
|
380
364
|
if (isThisExpression(node) || isSuper(node) || isTopicReference(node)) {
|
381
365
|
return true;
|
@@ -390,7 +374,6 @@ class Scope {
|
|
390
374
|
}
|
391
375
|
return false;
|
392
376
|
}
|
393
|
-
|
394
377
|
maybeGenerateMemoised(node, dontPush) {
|
395
378
|
if (this.isStatic(node)) {
|
396
379
|
return null;
|
@@ -407,11 +390,8 @@ class Scope {
|
|
407
390
|
}
|
408
391
|
checkBlockScopedCollisions(local, kind, name, id) {
|
409
392
|
if (kind === "param") return;
|
410
|
-
|
411
393
|
if (local.kind === "local") return;
|
412
|
-
const duplicate =
|
413
|
-
kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" ||
|
414
|
-
local.kind === "param" && kind === "const";
|
394
|
+
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const";
|
415
395
|
if (duplicate) {
|
416
396
|
throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
|
417
397
|
}
|
@@ -423,7 +403,6 @@ class Scope {
|
|
423
403
|
return new _renamer.default(binding, oldName, newName).rename(block);
|
424
404
|
}
|
425
405
|
}
|
426
|
-
|
427
406
|
_renameFromMap(map, oldName, newName, value) {
|
428
407
|
if (map[oldName]) {
|
429
408
|
map[newName] = value;
|
@@ -448,7 +427,6 @@ class Scope {
|
|
448
427
|
} while (scope = scope.parent);
|
449
428
|
console.log(sep);
|
450
429
|
}
|
451
|
-
|
452
430
|
toArray(node, i, arrayLikeIsIterable) {
|
453
431
|
if (isIdentifier(node)) {
|
454
432
|
const binding = this.getBinding(node.name);
|
@@ -470,7 +448,6 @@ class Scope {
|
|
470
448
|
helperName = "toConsumableArray";
|
471
449
|
} else if (typeof i === "number") {
|
472
450
|
args.push(numericLiteral(i));
|
473
|
-
|
474
451
|
helperName = "slicedToArray";
|
475
452
|
} else {
|
476
453
|
helperName = "toArray";
|
@@ -479,7 +456,6 @@ class Scope {
|
|
479
456
|
args.unshift(this.hub.addHelper(helperName));
|
480
457
|
helperName = "maybeArrayLike";
|
481
458
|
}
|
482
|
-
|
483
459
|
return callExpression(this.hub.addHelper(helperName), args);
|
484
460
|
}
|
485
461
|
hasLabel(name) {
|
@@ -552,7 +528,6 @@ class Scope {
|
|
552
528
|
if (local.identifier === id) continue;
|
553
529
|
this.checkBlockScopedCollisions(local, kind, name, id);
|
554
530
|
}
|
555
|
-
|
556
531
|
if (local) {
|
557
532
|
this.registerConstantViolation(bindingPath);
|
558
533
|
} else {
|
@@ -652,11 +627,9 @@ class Scope {
|
|
652
627
|
return isPureish(node);
|
653
628
|
}
|
654
629
|
}
|
655
|
-
|
656
630
|
setData(key, val) {
|
657
631
|
return this.data[key] = val;
|
658
632
|
}
|
659
|
-
|
660
633
|
getData(key) {
|
661
634
|
let scope = this;
|
662
635
|
do {
|
@@ -664,7 +637,6 @@ class Scope {
|
|
664
637
|
if (data != null) return data;
|
665
638
|
} while (scope = scope.parent);
|
666
639
|
}
|
667
|
-
|
668
640
|
removeData(key) {
|
669
641
|
let scope = this;
|
670
642
|
do {
|
@@ -706,17 +678,14 @@ class Scope {
|
|
706
678
|
}
|
707
679
|
path.traverse(collectorVisitor, state);
|
708
680
|
this.crawling = false;
|
709
|
-
|
710
681
|
for (const path of state.assignments) {
|
711
682
|
const ids = path.getBindingIdentifiers();
|
712
683
|
for (const name of Object.keys(ids)) {
|
713
684
|
if (path.scope.getBinding(name)) continue;
|
714
685
|
programParent.addGlobal(ids[name]);
|
715
686
|
}
|
716
|
-
|
717
687
|
path.scope.registerConstantViolation(path);
|
718
688
|
}
|
719
|
-
|
720
689
|
for (const ref of state.references) {
|
721
690
|
const binding = ref.scope.getBinding(ref.node.name);
|
722
691
|
if (binding) {
|
@@ -725,7 +694,6 @@ class Scope {
|
|
725
694
|
programParent.addGlobal(ref.node);
|
726
695
|
}
|
727
696
|
}
|
728
|
-
|
729
697
|
for (const path of state.constantViolations) {
|
730
698
|
path.scope.registerConstantViolation(path);
|
731
699
|
}
|
@@ -759,7 +727,6 @@ class Scope {
|
|
759
727
|
const len = declarPath.node.declarations.push(declarator);
|
760
728
|
path.scope.registerBinding(kind, declarPath.get("declarations")[len - 1]);
|
761
729
|
}
|
762
|
-
|
763
730
|
getProgramParent() {
|
764
731
|
let scope = this;
|
765
732
|
do {
|
@@ -769,7 +736,6 @@ class Scope {
|
|
769
736
|
} while (scope = scope.parent);
|
770
737
|
throw new Error("Couldn't find a Program");
|
771
738
|
}
|
772
|
-
|
773
739
|
getFunctionParent() {
|
774
740
|
let scope = this;
|
775
741
|
do {
|
@@ -779,7 +745,6 @@ class Scope {
|
|
779
745
|
} while (scope = scope.parent);
|
780
746
|
return null;
|
781
747
|
}
|
782
|
-
|
783
748
|
getBlockParent() {
|
784
749
|
let scope = this;
|
785
750
|
do {
|
@@ -789,7 +754,6 @@ class Scope {
|
|
789
754
|
} while (scope = scope.parent);
|
790
755
|
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
|
791
756
|
}
|
792
|
-
|
793
757
|
getPatternParent() {
|
794
758
|
let scope = this;
|
795
759
|
do {
|
@@ -799,7 +763,6 @@ class Scope {
|
|
799
763
|
} while (scope = scope.parent.parent);
|
800
764
|
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
|
801
765
|
}
|
802
|
-
|
803
766
|
getAllBindings() {
|
804
767
|
const ids = Object.create(null);
|
805
768
|
let scope = this;
|
@@ -813,7 +776,6 @@ class Scope {
|
|
813
776
|
} while (scope);
|
814
777
|
return ids;
|
815
778
|
}
|
816
|
-
|
817
779
|
getAllBindingsOfKind(...kinds) {
|
818
780
|
const ids = Object.create(null);
|
819
781
|
for (const kind of kinds) {
|
@@ -838,9 +800,7 @@ class Scope {
|
|
838
800
|
const binding = scope.getOwnBinding(name);
|
839
801
|
if (binding) {
|
840
802
|
var _previousPath;
|
841
|
-
|
842
|
-
if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {
|
843
|
-
} else {
|
803
|
+
if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {} else {
|
844
804
|
return binding;
|
845
805
|
}
|
846
806
|
} else if (!binding && name === "arguments" && scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
|
@@ -852,12 +812,10 @@ class Scope {
|
|
852
812
|
getOwnBinding(name) {
|
853
813
|
return this.bindings[name];
|
854
814
|
}
|
855
|
-
|
856
815
|
getBindingIdentifier(name) {
|
857
816
|
var _this$getBinding;
|
858
817
|
return (_this$getBinding = this.getBinding(name)) == null ? void 0 : _this$getBinding.identifier;
|
859
818
|
}
|
860
|
-
|
861
819
|
getOwnBindingIdentifier(name) {
|
862
820
|
const binding = this.bindings[name];
|
863
821
|
return binding == null ? void 0 : binding.identifier;
|
@@ -865,7 +823,6 @@ class Scope {
|
|
865
823
|
hasOwnBinding(name) {
|
866
824
|
return !!this.getOwnBinding(name);
|
867
825
|
}
|
868
|
-
|
869
826
|
hasBinding(name, opts) {
|
870
827
|
var _opts, _opts2, _opts3;
|
871
828
|
if (!name) return false;
|
@@ -885,7 +842,6 @@ class Scope {
|
|
885
842
|
var _this$parent;
|
886
843
|
return (_this$parent = this.parent) == null ? void 0 : _this$parent.hasBinding(name, opts);
|
887
844
|
}
|
888
|
-
|
889
845
|
moveBindingTo(name, scope) {
|
890
846
|
const info = this.getBinding(name);
|
891
847
|
if (info) {
|
@@ -900,7 +856,6 @@ class Scope {
|
|
900
856
|
removeBinding(name) {
|
901
857
|
var _this$getBinding2;
|
902
858
|
(_this$getBinding2 = this.getBinding(name)) == null ? void 0 : _this$getBinding2.scope.removeOwnBinding(name);
|
903
|
-
|
904
859
|
let scope = this;
|
905
860
|
do {
|
906
861
|
if (scope.uids[name]) {
|