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

Add test for issue 12570 #15750

Merged
merged 1 commit into from
Jul 5, 2023
Merged
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
37 changes: 36 additions & 1 deletion packages/babel-traverse/test/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe("traverse", function () {
expect(visited).toBe(true);
});
});
describe("path.visit()", () => {
describe("path.traverse()", () => {
it("should preserve traversal context after enter hook is executed", () => {
const ast = parse("{;}");
// The test initiates a sub-traverse from program. When the `enter` hook of BlockStatement
Expand Down Expand Up @@ -278,6 +278,41 @@ describe("traverse", function () {
});
expect(blockStatementVisitedCounter).toBe(1);
});
it("regression - #12570", () => {
const logs = [];

const ast = parse(
`
import { Foo } from './Foo'
import { Bar } from './Bar'
`,
{ sourceType: "module" },
);
traverse(ast, {
Program(path) {
path.traverse({
ImportDeclaration: {
enter(path) {
logs.push(["ENTER", path.node.source.value]);
if (path.node.source.value === "./Bar") {
path.parentPath.get(path.listKey);
}
},
exit(path) {
logs.push(["EXIT", path.node.source.value]);
},
},
});
},
});

expect(logs).toEqual([
["ENTER", "./Foo"],
["EXIT", "./Foo"],
["ENTER", "./Bar"],
["EXIT", "./Bar"],
]);
});
});
describe("path.stop()", () => {
it("should stop the traversal when a grand child is stopped", () => {
Expand Down