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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix duplicate declaration error
  • Loading branch information
The-x-Theorist committed Dec 2, 2021
commit dbc8b035ea6ef87ae39a60b2e6ffba340fb88c7e
2 changes: 2 additions & 0 deletions packages/babel-traverse/src/scope/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,8 @@ export default class Scope {
for (const declar of declarations) {
this.registerBinding(path.node.kind, declar);
}
} else if(path.isClassDeclaration() && path.node.declare) {
this.registerBinding("class", path);
} else if (path.isClassDeclaration()) {
this.registerBinding("let", path);
The-x-Theorist marked this conversation as resolved.
Show resolved Hide resolved
} else if (path.isImportDeclaration()) {
Expand Down
12 changes: 12 additions & 0 deletions packages/babel-traverse/test/scope.js
Original file line number Diff line number Diff line change
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