-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Conversation
@@ -285,14 +291,10 @@ module.exports = ({ types: t, traverse }) => { | |||
let replacementPath = binding.path; | |||
let isReferencedBefore = false; | |||
|
|||
if (binding.referencePaths.length > 1) { |
There was a problem hiding this comment.
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) || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use || {}
?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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);
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 |
var hoisting was considered earlier. But I didn't try measuring its effect on gzip yet. #48 (comment) |
Hmm alright, the problem itself is with babel's It becomes tricky to do the scope check on every pattern matching step in simplify. |
d7f8de5
to
20c2f81
Compare
20c2f81
to
57fe8ff
Compare
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.