-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
babel-plugin-minify-dead-code-elimination SequenceExpression
use case
#373
Comments
SequenceExpression
problemSequenceExpression
use case
Thanks for reporting, definitely a valid use case. |
Thanks for replying! I don't suppose I can help? |
It's an unsafe transformation - function f1() {
return 1, 2, void 0;
}
function f2() {
return 1, 2;
}
console.log(f1(), f2()); // will print undefined, 2 |
@boopathi when the parent is an Also when the //Any other statement with an expression that contains a sequence expression
let g = (void 0, void 0, 1);
//becomes
let g = (1);
//ExpressionStatement (SequenceExpression)
void 0, 1, 2, 3, void 0;
//becomes
1, 2, 3;
//taking your example
function f1() {
return 1, void 0, 2, void 0;
}
function f2() {
return 1, 2, void 0;
}
console.log(f1(), f2()); // will print 2
|
Example visitor that might be useful. Check out this example here. It should be correct. For some reason the transformation yields two sequence expressions (and it looks like a babel bug!) but the general idea here is that some |
This is similar to #197 where we remove |
Thanks guys! This is really awesome. |
@kangax do you detect to see if |
You're right, it's unsafe. I looked into fixing it in Babili, then realized it has to do with Babel's |
SequenceExpression
inExpressionStatement
containingUnaryExpression(void 0)
does not remove dead code.I realize this is a small use case, but if an
ExpressionStatement
contains aSequenceExpression
with void 0 it can be removed with no worry of side-effects.should be:
Thanks for reading!
-Josh
The text was updated successfully, but these errors were encountered: