Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate declaration error on ambient class declarations #14016

Merged
merged 3 commits into from Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
The-x-Theorist marked this conversation as resolved.
Show resolved Hide resolved
} 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