Skip to content

Commit

Permalink
Fix duplicate declaration error on ambient class declarations (#14016)
Browse files Browse the repository at this point in the history
  • Loading branch information
The-x-Theorist committed Dec 5, 2021
1 parent 2d989a9 commit a943f57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/babel-traverse/src/scope/index.ts
Expand Up @@ -706,6 +706,7 @@ export default class Scope {
this.registerBinding(path.node.kind, declar);
}
} else if (path.isClassDeclaration()) {
if (path.node.declare) return;
this.registerBinding("let", path);
} else if (path.isImportDeclaration()) {
const specifiers = path.get("specifiers");
Expand Down
12 changes: 12 additions & 0 deletions packages/babel-traverse/test/scope.js
Expand Up @@ -655,6 +655,18 @@ describe("scope", () => {
});
});

describe("duplicate declaration", () => {
it("should not throw error on duplicate class and function declaration", () => {
const ast = [
t.classDeclaration(t.identifier("A"), t.super(), t.classBody([]), []),
t.functionDeclaration(t.identifier("A"), [], t.blockStatement([])),
];

ast[0].declare = true;
expect(() => getPath(ast)).not.toThrowError();
});
});

describe("global", () => {
// node1, node2, success
// every line will run 2 tests `node1;node2;` and `node2;node1;`
Expand Down

0 comments on commit a943f57

Please sign in to comment.