-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
test: add tests about behaviour of replaceWithMultiple #12309
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
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:
|
existentialism
left a comment
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#replaceWithMultiplebehaviour 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.nodebyn, w.l.o.g. we assumenodes[0] === n), we don't update thepathCacheof its parent.babel/packages/babel-traverse/src/path/index.js
Line 70 in 12c6db6
Since the
pathCacheholds a NodePath which has a reference to then, it implicitly copynto a new memory address. Now when thenis queried againstpathCachebabel/packages/babel-traverse/src/path/index.js
Line 79 in 12c6db6
The
pathCacheis missed because the NodePath is referencing a shallow copy ofn, so a new NodePath instance is created fornandthis.nodeis alwaysnullduringbabel/packages/babel-traverse/src/path/replacement.js
Lines 53 to 59 in 12c6db6
then it is removed instead of
requeueso this node is never visited after replaced.I think intuitively all nodes in the argument of
replaceWithMultipleshould be revisited. But the suggested behaviour is a breaking change, e.g. breaking TDZ implementation.