Skip to content
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

Require blocks around single block-scope declaration #220

Merged
merged 2 commits into from
Oct 26, 2016

Conversation

boopathi
Copy link
Member

@boopathi boopathi commented Oct 25, 2016

The var declaration removal should be done in DCE instead of simplify. This is necessary as simplify as a standalone plugin should not produce syntax errors.

A single block scoped declaration under an if/else requires a block
statement. The block statement here if removed is a syntax error and
this removal of block statement is valid only for vars and not for let
or const.

We could essentially go ahead and remove the left hand side of the
variable declaration, but that is the job of the DeadCode elimination
plugin. Here, we just correct the mistake and let simplify generate
correct output when used in isolation. Let dead code take care of
removal of block and the left hand side of the declaration
@kangax
Copy link
Member

kangax commented Oct 25, 2016

Will this work with else { function x() { } ... }?

@boopathi
Copy link
Member Author

if(true) function x() {} or else function x() {} is not syntax error.

@boopathi
Copy link
Member Author

boopathi commented Oct 25, 2016

It is in strict mode though. Will add block for function anyway.

@kangax kangax merged commit 98aa805 into master Oct 26, 2016
@kangax kangax deleted the simplify-block-scope-block-0 branch October 26, 2016 18:37
@boopathi boopathi added this to the 0.0.8 milestone Oct 30, 2016
@hzoo hzoo added the bug Confirmed bug label Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

var declaration inlined incorrectly in conditional
3 participants