Fix duplicate declaration error on ambient class declarations (#14016)

This commit is contained in:
Sneh Khatri 2021-12-05 22:54:56 +05:30 committed by GitHub
parent 2d989a983d
commit a943f576d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -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");

View File

@ -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;`