Skip to content

Commit

Permalink
test: add tests about behaviour of replaceWithMultiple
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 4, 2020
1 parent 12c6db6 commit 1834103
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/babel-traverse/test/replacement.js
Expand Up @@ -112,5 +112,20 @@ describe("path/replacement", function () {
});
expect(generate(ast).code).toBe("<div><p></p><h></h></div>;");
});
it("does not revisit one of new nodes if it is the node being replaced", () => {
// packages/babel-plugin-transform-block-scoping/src/index.js relies on this behaviour
const ast = parse(`var x;`);
let visitCounter = 0;
traverse(ast, {
VariableDeclaration(path) {
visitCounter++;
if (visitCounter > 2) {
return true;
}
path.replaceWithMultiple([path.node, t.emptyStatement()]);
},
});
expect(visitCounter).toBe(1);
});
});
});

0 comments on commit 1834103

Please sign in to comment.