-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Static analysis to eliminate dead code #1061
Comments
This is a two-parter – first, the commonjs plugin would need to rewrite the Second, Rollup's dead code elimination would need to handle logical expressions in |
statically analyse LogicalExpression nodes
Fixed in 0.38.3 and [email protected] |
Great stuff. I guess the next logical step would be to add another bit of functionality to remove curly braces around blocks without {
console.log( 'true' );
} Or perhaps just leave that to the downstream minifier to deal with. |
Yeah, I think Rollup should ideally remove the braces. Minifiers will remove them, so it's not a super high priority, but it does look weird if they're not removed. Not just |
So just a matter of descending the block AST and if those 4 constructs are not found then the braces can be removed? |
Think so yeah. Wouldn't even need to walk the BlockStatement since any declarations would have to be direct descendants of it, I think, so off the top of my head: const blockScopedDeclarations = block.children.filter( node =>
/Declaration/.test( node.type ) && node.kind !== 'var' );
if ( blockScopedDeclarations.length === 0 ) {
// remove curlies. for extra credit, deindent...
} |
webpack
is able to do static analysis on the following UMD code to remove it whilerollup
leaves it behind.this should be replace by
which can then be eliminated
The text was updated successfully, but these errors were encountered: