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

[DCE] Fix var hoisting #169

Merged
merged 1 commit into from
Sep 30, 2016
Merged

[DCE] Fix var hoisting #169

merged 1 commit into from
Sep 30, 2016

Conversation

boopathi
Copy link
Member

One other option to handle this will be to hoist var declarations as one of the first plugins. But @amasad had concerns with the hoisting effect on gzip in #52 . So this approach is okay IMO.

a = 1; return a; var a; could not be reduced to return 1 because we don't have the flow of control in the program - this is here in babel - babel/babel#4420

@@ -895,4 +895,10 @@ module.exports = ({ types: t, traverse }) => {
};
}
}

// things that are hoisted
function canExistAfterCompletion(path) {
Copy link
Member

Choose a reason for hiding this comment

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

So basically anything that doesn't conform to TDZ? What about function?

a = 1;
return a;
function a() { }

Copy link
Member Author

@boopathi boopathi Sep 29, 2016

Choose a reason for hiding this comment

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

That test is already covered in name=should be fine with fun decl after return if that's what you meant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah, perfect!

Fix bug where var declarations after compleition statements are
deadcode eliminated - vars are hoisted in JS and need to be preserved
like function declarations

(Close #167)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants