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
Last case clauses should be tree-shaken when empty #3164
Comments
Any
Be aware that the
@lukastaegert Slightly off topic... Are the internal ASTs themselves generally updated in such transforms or are just MagicString code string manipulations performed? If the latter at some point repeated application of various transforms would cease to work I would think. |
In general any break inside a switch where there are no further side-effects in any of the cases after it. I think this would be a nice-to-have but will not provide any further tree-shaking benefits that would remove additional code. Note that a switch statements that does not contain side-effects will be removed entirely even if it contains break statements: https://rollupjs.org/repl/?version=1.24.0&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMnN3aXRjaCUyMChnbG9iYWxUaGlzLnVua25vd24pJTIwJTdCJTVDbiU1Q3RjYXNlJTIwMSUzQSU1Q24lNUN0JTVDdGNvbnN0JTIwdW51c2VkJTIwJTNEJTIwMSUzQiU1Q24lNUN0JTVDdGJyZWFrJTNCJTVDbiU1Q3QlNUN0Y29uc29sZS5sb2coJ2RlYWQlMjBjb2RlJyklM0IlNUNuJTVDdGRlZmF1bHQlM0ElNUNuJTVDdCU1Q3RicmVhayUzQiU1Q24lN0QlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlc20lMjIlMkMlMjJuYW1lJTIyJTNBJTIybXlCdW5kbGUlMjIlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlN0QlMkMlMjJleGFtcGxlJTIyJTNBbnVsbCU3RA== If someone is interested, I will leave this issue for someone to pick it up put I will probably not tackle it.
The AST is never modified as otherwise we would need to include an entire mechanic to regenerate the code from the AST, which would very much bloat Rollup and is not a goal. If done right, until now, MagicString was capable of dealing with the necessary transformations and it would have no issues with the transformations described here if they are done on the right level. |
On second though, the case expressions themselves could reference variables that might be tree-shaken. Maybe I will give it another though. Removing trailing break-statements, just as trailing continue statements or returns, will not provide any additional benefit, though. |
I don't think it's generally safe to remove trailing continue statements or returns in a switch.
|
Sorry, I was skipping topic here. |
Ah I see. I will try to tackle it in #3166 |
I added a fix |
@lukastaegert Regarding ASTs and MagicString, you may find this interesting: https://twitter.com/mikesherov/status/1184673919279751172 I have great respect for the work done with MagicString, but I do think Rollup could benefit from direct AST transformation as it becomes an optimizing compiler in its own right. |
How Do We Reproduce?
Expected Behavior
Actual Behavior
The text was updated successfully, but these errors were encountered: