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
[tree-shaking] function with no side-effects & args included in output #2539
Comments
hmm, i guess the title is not quite correct. the function does mutate the arguments, but those args are never used or exported afterwards. this might be a tricky case, not even Closure Compiler is able to strip this out in ADVANCED mode :( support for the for the time being i'm able to work around this by using a regex replace plugin [1] to create a no-op replace({
patterns: [
{
test: /^const.*require.*extend.*/gm,
replace: 'const extend = () => {};',
}
]
}) |
I guess static side-effects analysis will always reach limitations for dynamic parts. #5024 introduced the annotation to manually mark functions as side-effects-free, which I think should be able to solve this issue. |
Repro:
https://rollupjs.org/repl?version=0.66.6&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMGV4dGVuZCUyMCU3RCUyMGZyb20lMjAnLiUyRmV4dGVuZC5qcyclM0IlNUNuJTVDbmZ1bmN0aW9uJTIwRm9vKCklMjAlN0IlN0QlNUNuJTVDbmZ1bmN0aW9uJTIwQmFyKCklMjAlN0IlN0QlNUNuJTVDbmV4dGVuZChGb28lMkMlMjBCYXIlMkMlMjAlN0IlN0QpJTNCJTVDbiU1Q25jb25zdCUyMGJheiUyMCUzRCUyMDUlM0IlNUNuJTVDbmV4cG9ydCUyMGRlZmF1bHQlMjBiYXolM0IlMjIlN0QlMkMlN0IlMjJuYW1lJTIyJTNBJTIyZXh0ZW5kLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMGZ1bmN0aW9uJTIwZXh0ZW5kKHBhcmVudCUyQyUyMGNoaWxkJTJDJTIwcHJvcHMpJTIwJTdCJTVDbiU1Q3RjaGlsZC5fX3Byb3RvX18lMjAlM0QlMjBwYXJlbnQlM0IlNUNuJTVDdHZhciUyMHByb3Rv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