Skip to content

Path#ensureBlock keeps path context#6337

Merged
jridgewell merged 2 commits intobabel:masterfrom
jridgewell:ensureBlock
Sep 29, 2017
Merged

Path#ensureBlock keeps path context#6337
jridgewell merged 2 commits intobabel:masterfrom
jridgewell:ensureBlock

Conversation

@jridgewell
Copy link
Copy Markdown
Member

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#push caused my visitor to suddenly stop working. Now, we mutate the Path so it's still in the tree.

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.
@jridgewell
Copy link
Copy Markdown
Member Author

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Sep 29, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5096/

@jridgewell jridgewell mentioned this pull request Sep 29, 2017
Copy link
Copy Markdown
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
;
Copy link
Copy Markdown
Member

@hzoo hzoo Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know where this one's coming from.

@jridgewell
Copy link
Copy Markdown
Member Author

Tests added.

@hzoo hzoo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Sep 29, 2017
@jridgewell jridgewell merged commit 3746273 into babel:master Sep 29, 2017
@jridgewell jridgewell deleted the ensureBlock branch September 29, 2017 23:00
@jridgewell jridgewell restored the ensureBlock branch April 9, 2018 17:25
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants