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 .parentPath after rename in SwitchCase #15287

Merged
Merged
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions packages/babel-traverse/test/scope.js
Expand Up @@ -1002,4 +1002,24 @@ describe("scope", () => {
expect(program.scope.hasOwnBinding("ref")).toBe(true);
});
});

describe("rename", () => {
it(".parentPath after renaming variable in switch", () => {
const program = getPath(`
switch (x) {
case y:
let a;
}
`);
program.traverse({
VariableDeclaration(path) {
if (path.node.declarations[0].id.name !== "a") return;

expect(path.parentPath.type).toBe("SwitchCase");
path.scope.rename("a");
expect(path.parentPath.type).toBe("SwitchCase");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently SwitchStatement on main.

},
});
});
});
});