Skip to content

Commit

Permalink
Fixed issue with programPath.scope.references not being registered ba…
Browse files Browse the repository at this point in the history
…ck correctly after scope re-crawling
  • Loading branch information
Andarist committed Mar 23, 2020
1 parent 9b976b2 commit 6c5b35d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/babel-traverse/src/scope/index.js
Expand Up @@ -609,6 +609,8 @@ export default class Scope {
const ids = path.getOuterBindingIdentifiers(true);

for (const name of Object.keys(ids)) {
parent.references[name] = true;

for (const id of (ids[name]: Array<Object>)) {
const local = this.getOwnBinding(name);

Expand All @@ -620,8 +622,6 @@ export default class Scope {
this.checkBlockScopedCollisions(local, kind, name, id);
}

parent.references[name] = true;

// A redeclaration of an existing variable is a modification
if (local) {
this.registerConstantViolation(bindingPath);
Expand Down
9 changes: 9 additions & 0 deletions packages/babel-traverse/test/scope.js
Expand Up @@ -303,6 +303,15 @@ describe("scope", () => {

expect(path.scope.bindings.a).toBe(path.get("body[0]").scope.bindings.a);
});

it("references after re-crawling", function() {
const path = getPath("function Foo() { var jsx; }");

path.scope.crawl();
path.scope.crawl();

expect(path.scope.references.jsx).toBeTruthy();
});
});

describe("duplicate bindings", () => {
Expand Down

0 comments on commit 6c5b35d

Please sign in to comment.