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
test: add tests about behaviour of replaceWithMultiple #12309
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/31802/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 0eb5214:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if |
I'm not sure that I would expect that behavior. However, I think it should match whatever |
The order does not matters since they are created in a loop babel/packages/babel-traverse/src/path/modification.js Lines 57 to 65 in 12c6db6
but I have added another tests.
Yeah babel/packages/babel-traverse/src/path/replacement.js Lines 119 to 121 in 12c6db6
but it does requeue for other cases. babel/packages/babel-traverse/src/path/replacement.js Lines 178 to 179 in 12c6db6
|
942a37e
to
0eb5214
Compare
Add a test on the
NodePath#replaceWithMultiple
behaviour when one of node is the replaced node. This tests is required by #12302, I feel it should be landed separately.This behaviour is not intuitive to me. It is not visited because in
babel/packages/babel-traverse/src/path/replacement.js
Lines 46 to 52 in 12c6db6
when we clear
this.node
(we denotethis.node
byn
, w.l.o.g. we assumenodes[0] === n
), we don't update thepathCache
of its parent.babel/packages/babel-traverse/src/path/index.js
Line 70 in 12c6db6
Since the
pathCache
holds a NodePath which has a reference to then
, it implicitly copyn
to a new memory address. Now when then
is queried againstpathCache
babel/packages/babel-traverse/src/path/index.js
Line 79 in 12c6db6
The
pathCache
is missed because the NodePath is referencing a shallow copy ofn
, so a new NodePath instance is created forn
andthis.node
is alwaysnull
duringbabel/packages/babel-traverse/src/path/replacement.js
Lines 53 to 59 in 12c6db6
then it is removed instead of
requeue
so this node is never visited after replaced.I think intuitively all nodes in the argument of
replaceWithMultiple
should be revisited. But the suggested behaviour is a breaking change, e.g. breaking TDZ implementation.