Skip to content

Commit a943f57

Browse files
Fix duplicate declaration error on ambient class declarations (#14016)
1 parent 2d989a9 commit a943f57

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

packages/babel-traverse/src/scope/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ export default class Scope {
706706
this.registerBinding(path.node.kind, declar);
707707
}
708708
} else if (path.isClassDeclaration()) {
709+
if (path.node.declare) return;
709710
this.registerBinding("let", path);
710711
} else if (path.isImportDeclaration()) {
711712
const specifiers = path.get("specifiers");

packages/babel-traverse/test/scope.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,18 @@ describe("scope", () => {
655655
});
656656
});
657657

658+
describe("duplicate declaration", () => {
659+
it("should not throw error on duplicate class and function declaration", () => {
660+
const ast = [
661+
t.classDeclaration(t.identifier("A"), t.super(), t.classBody([]), []),
662+
t.functionDeclaration(t.identifier("A"), [], t.blockStatement([])),
663+
];
664+
665+
ast[0].declare = true;
666+
expect(() => getPath(ast)).not.toThrowError();
667+
});
668+
});
669+
658670
describe("global", () => {
659671
// node1, node2, success
660672
// every line will run 2 tests `node1;node2;` and `node2;node1;`

0 commit comments

Comments
 (0)