Skip to content

Commit

Permalink
Merge path.crawl ClassDeclaration and Declaration visitors
Browse files Browse the repository at this point in the history
Merged to avoid subtle assumption that `Declaration` is called before `ClassDeclaration`
  • Loading branch information
regiontog committed Jan 15, 2020
1 parent 5c0b0ac commit 63a12f2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/babel-traverse/src/scope/index.js
Expand Up @@ -72,6 +72,14 @@ const collectorVisitor = {
const parent =
path.scope.getFunctionParent() || path.scope.getProgramParent();
parent.registerDeclaration(path);

// Register class identifier in class' scope if this is a class declaration.
if (path.isClassDeclaration() && path.node.id) {
const id = path.node.id;
const name = id.name;

path.scope.bindings[name] = parent.getBinding(name);
}
},

ReferencedIdentifier(path, state) {
Expand Down Expand Up @@ -131,14 +139,6 @@ const collectorVisitor = {
scope.getBlockParent().registerDeclaration(path);
},

ClassDeclaration(path) {
const id = path.node.id;
if (!id) return;

const name = id.name;
path.scope.bindings[name] = path.scope.parent.getBinding(name);
},

Block(path) {
const paths = path.get("body");
for (const bodyPath of (paths: Array)) {
Expand Down

0 comments on commit 63a12f2

Please sign in to comment.