Skip to content

Commit

Permalink
Add test for issue 12570 (#15750)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jul 5, 2023
1 parent b60e0c2 commit e5c78d1
Showing 1 changed file with 36 additions and 1 deletion.
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

0 comments on commit e5c78d1

Please sign in to comment.