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

[fix #574] deopt when binding is present in diff scope #597

Merged
merged 4 commits into from
Aug 7, 2017
Merged

Conversation

vigneshshanmugam
Copy link
Member

@vigneshshanmugam vigneshshanmugam commented Jun 21, 2017

this is required for only var bindings.

The other way we could fix this is to hoist all the var bindings before we run simplify & deadcode.

@@ -285,14 +291,10 @@ module.exports = ({ types: t, traverse }) => {
let replacementPath = binding.path;
let isReferencedBefore = false;

if (binding.referencePaths.length > 1) {
Copy link
Member Author

Choose a reason for hiding this comment

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

unnecessary check.

@@ -765,8 +767,21 @@ module.exports = ({ types: t, traverse }) => {
const evalResult = test.evaluate();
const isPure = test.isPure();

const replacements = [];
const { path: bindingPath } =
path.scope.getBinding(test.node.name) || {};
Copy link
Member

Choose a reason for hiding this comment

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

don't use || {} ?

Copy link
Member

Choose a reason for hiding this comment

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

if (binding) check is clearer, like it's used everywhere else in babili

const source = unpad(`
function foo(v) {
if (v) var w = 10;
if (w) console.log("hello", v);
Copy link
Member

Choose a reason for hiding this comment

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

There is also

while (v) { var w = 10; }
if (w) console.log(w);

@vigneshshanmugam
Copy link
Member Author

We need to handle this in simplify as well for the same case.

Started to think, hoisting that var would be a better option than monkey patching at all places. Thoughts? @boopathi

@boopathi
Copy link
Member

var hoisting was considered earlier. But I didn't try measuring its effect on gzip yet. #48 (comment)

@vigneshshanmugam
Copy link
Member Author

Hmm alright, the problem itself is with babel's path.evaluate() being truthy even for bindings present in different scope.

It becomes tricky to do the scope check on every pattern matching step in simplify.

@boopathi boopathi merged commit 19720cb into master Aug 7, 2017
@boopathi boopathi deleted the scope-fix branch August 7, 2017 19:46
@boopathi boopathi added the Tag: Bug Fix Pull Request fixes a bug label Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tag: Bug Fix Pull Request fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

if statement wrongly removed when var declaration inside conditional block
2 participants