Path#ensureBlock keeps path context#6337
Conversation
This ensures that if you're inside an ArrowFunction with an expression body (say, you're on the BooleanLiteral in `() => true`), you don't suddenly lose your path context after inserting a variable. This is because of babel@82d8ade#diff-9e0668ad44535be897b934e7077ecea5R14. Basically, an innocent `Scope#push` caused my visitor to suddenly stop working. Now, we mutate the Path so it's still in the tree.
|
Basically this shows the issue: http://astexplorer.net/#/gist/2046589d3a9a4a1af792584a43997d97/c8d710c11713e48139ea557188d5c34fdbc7d4d6. I'm too sleepy to put together words into an reasonable description. |
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5096/ |
There was a problem hiding this comment.
lgtm, can we have a unit test for this somehow though?
or just get coverage for path.ensureBlock in https://github.com/babel/babel/tree/master/packages/babel-traverse/test
Didn't realize there was a path.ensureBlock and a t.ensureBlock too
|
|
||
| for (MULTIPLIER in arr) { | ||
| throw new Error("\"MULTIPLIER\" is read-only"); | ||
| ; |
There was a problem hiding this comment.
Always curious why we have these empty statements, is there a way to remove (or would that be a weird side effect if we filtered them out of the ast?
There was a problem hiding this comment.
I don't really know where this one's coming from.
|
Tests added. |
This ensures that if you're inside an ArrowFunction with an expression body (say, you're on the BooleanLiteral in
() => true), you don't suddenly lose your path context after inserting a variable.This is because of 82d8ade#diff-9e0668ad44535be897b934e7077ecea5R14. Basically, an innocent
Scope#pushcaused my visitor to suddenly stop working. Now, we mutate the Path so it's still in the tree.