@babel/traverse 7.9.0 → 7.9.5

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.

Files changed (2) hide show
  1. package/lib/scope/index.js +35 -36
  2. package/package.json +5 -5
@@ -270,6 +270,28 @@ const collectorVisitor = {
270
270
  path.scope.getBlockParent().registerDeclaration(bodyPath);
271
271
  }
272
272
  }
273
+ },
274
+
275
+ CatchClause(path) {
276
+ path.scope.registerBinding("let", path);
277
+ },
278
+
279
+ Function(path) {
280
+ if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
281
+ path.scope.registerBinding("local", path.get("id"), path);
282
+ }
283
+
284
+ const params = path.get("params");
285
+
286
+ for (const param of params) {
287
+ path.scope.registerBinding("param", param);
288
+ }
289
+ },
290
+
291
+ ClassExpression(path) {
292
+ if (path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
293
+ path.scope.registerBinding("local", path);
294
+ }
273
295
  }
274
296
 
275
297
  };
@@ -293,6 +315,7 @@ class Scope {
293
315
  this.block = node;
294
316
  this.path = path;
295
317
  this.labels = new Map();
318
+ this.inited = false;
296
319
  }
297
320
 
298
321
  get parent() {
@@ -547,6 +570,8 @@ class Scope {
547
570
  const ids = path.getOuterBindingIdentifiers(true);
548
571
 
549
572
  for (const name of Object.keys(ids)) {
573
+ parent.references[name] = true;
574
+
550
575
  for (const id of ids[name]) {
551
576
  const local = this.getOwnBinding(name);
552
577
 
@@ -555,8 +580,6 @@ class Scope {
555
580
  this.checkBlockScopedCollisions(local, kind, name, id);
556
581
  }
557
582
 
558
- parent.references[name] = true;
559
-
560
583
  if (local) {
561
584
  this.registerConstantViolation(bindingPath);
562
585
  } else {
@@ -596,13 +619,7 @@ class Scope {
596
619
  }
597
620
 
598
621
  hasReference(name) {
599
- let scope = this;
600
-
601
- do {
602
- if (scope.references[name]) return true;
603
- } while (scope = scope.parent);
604
-
605
- return false;
622
+ return !!this.getProgramParent().references[name];
606
623
  }
607
624
 
608
625
  isPure(node, constantsOnly) {
@@ -682,7 +699,10 @@ class Scope {
682
699
  }
683
700
 
684
701
  init() {
685
- if (!this.references) this.crawl();
702
+ if (!this.inited) {
703
+ this.inited = true;
704
+ this.crawl();
705
+ }
686
706
  }
687
707
 
688
708
  crawl() {
@@ -693,26 +713,11 @@ class Scope {
693
713
  this.uids = Object.create(null);
694
714
  this.data = Object.create(null);
695
715
 
696
- if (path.isLoop()) {
697
- for (const key of t.FOR_INIT_KEYS) {
698
- const node = path.get(key);
699
- if (node.isBlockScoped()) this.registerBinding(node.node.kind, node);
700
- }
701
- }
702
-
703
- if (path.isFunctionExpression() && path.has("id")) {
704
- if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
716
+ if (path.isFunction()) {
717
+ if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
705
718
  this.registerBinding("local", path.get("id"), path);
706
719
  }
707
- }
708
-
709
- if (path.isClassExpression() && path.has("id")) {
710
- if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
711
- this.registerBinding("local", path);
712
- }
713
- }
714
720
 
715
- if (path.isFunction()) {
716
721
  const params = path.get("params");
717
722
 
718
723
  for (const param of params) {
@@ -720,12 +725,8 @@ class Scope {
720
725
  }
721
726
  }
722
727
 
723
- if (path.isCatchClause()) {
724
- this.registerBinding("let", path);
725
- }
726
-
727
- const parent = this.getProgramParent();
728
- if (parent.crawling) return;
728
+ const programParent = this.getProgramParent();
729
+ if (programParent.crawling) return;
729
730
  const state = {
730
731
  references: [],
731
732
  constantViolations: [],
@@ -737,11 +738,9 @@ class Scope {
737
738
 
738
739
  for (const path of state.assignments) {
739
740
  const ids = path.getBindingIdentifiers();
740
- let programParent;
741
741
 
742
742
  for (const name of Object.keys(ids)) {
743
743
  if (path.scope.getBinding(name)) continue;
744
- programParent = programParent || path.scope.getProgramParent();
745
744
  programParent.addGlobal(ids[name]);
746
745
  }
747
746
 
@@ -754,7 +753,7 @@ class Scope {
754
753
  if (binding) {
755
754
  binding.reference(ref);
756
755
  } else {
757
- ref.scope.getProgramParent().addGlobal(ref.node);
756
+ programParent.addGlobal(ref.node);
758
757
  }
759
758
  }
760
759
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.9.0",
3
+ "version": "7.9.5",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
5
  "author": "Sebastian McKenzie <sebmck@gmail.com>",
6
6
  "homepage": "https://babeljs.io/",
@@ -12,11 +12,11 @@
12
12
  "main": "lib/index.js",
13
13
  "dependencies": {
14
14
  "@babel/code-frame": "^7.8.3",
15
- "@babel/generator": "^7.9.0",
16
- "@babel/helper-function-name": "^7.8.3",
15
+ "@babel/generator": "^7.9.5",
16
+ "@babel/helper-function-name": "^7.9.5",
17
17
  "@babel/helper-split-export-declaration": "^7.8.3",
18
18
  "@babel/parser": "^7.9.0",
19
- "@babel/types": "^7.9.0",
19
+ "@babel/types": "^7.9.5",
20
20
  "debug": "^4.1.0",
21
21
  "globals": "^11.1.0",
22
22
  "lodash": "^4.17.13"
@@ -24,5 +24,5 @@
24
24
  "devDependencies": {
25
25
  "@babel/helper-plugin-test-runner": "^7.8.3"
26
26
  },
27
- "gitHead": "8d5e422be27251cfaadf8dd2536b31b4a5024b02"
27
+ "gitHead": "5b97e77e030cf3853a147fdff81844ea4026219d"
28
28
  }