Skip to content
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

Dead code detection too aggressive on array prototype mutation #4425

Closed
maximilianMairinger opened this issue Mar 3, 2022 · 3 comments · Fixed by #4428
Closed

Dead code detection too aggressive on array prototype mutation #4425

maximilianMairinger opened this issue Mar 3, 2022 · 3 comments · Fixed by #4428

Comments

@maximilianMairinger
Copy link

Rollup Version

2.69.0

Operating System (or Browser)

MacOs chrome

Node Version (if applicable)

No response

Link To Reproduction

https://rollupjs.org/repl/?version=2.69.0&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmNvbnN0JTIwYXJyJTIwJTNEJTIwJTVCJTVEJTIwJTJGJTJGJTIwbmV3JTIwQXJyYXkoKSUyMCUyRiUyRiUyMHdvdWxkJTIwd29yayU1Q24lNUNuJTVDbk9iamVjdC5kZWZpbmVkUHJvcGVydHkoQXJyYXkucHJvdG90eXBlJTJDJTIwJTVDJTIyaXNFbXB0eSU1QyUyMiUyQyUyMCU3QiUyMCUyRiUyRiUyME9iamVjdC5kZWZpbmVkUHJvcGVydHkoYXJyJTIwJTJGJTJGJTIwd291bGQlMjB3b3JrJTVDbiUyMCUyMGdldCgpJTIwJTdCJTVDbiU1Q3QlMjAlMjByZXR1cm4lMjB0aGlzLmxlbCUyMCUzRCUzRCUzRCUyMDAlNUNuJTVDdCU3RCU1Q24lN0QpJTVDbiU1Q25jb25zdCUyMGYlMjAlM0QlMjAoKSUyMCUzRCUzRSUyMCU3QiU1Q24lMjAlMjBpZiUyMChhcnIuaXNFbXB0eSklMjBjb25zb2xlLmxvZyglNUMlMjJXT1JLUyU1QyUyMiklMjAlMkYlMkYlMjBhcnIuaXNFbXB0eSgpJTIwJTJGJTJGJTIwd291bGQlMjB3b3JrJTVDbiUyMCUyMGVsc2UlMjBjb25zb2xlLmxvZyglNUMlMjIuLi4lNUMlMjIpJTVDbiU1Q3QlNUNuJTIwJTIwYXJyLnB1c2goJTVDJTIyd2hhdGV2ZXIlNUMlMjIpJTIwJTJGJTJGJTIwcmVzdGFydGluZ0NvdXNPZi5sZW5ndGglMkIlMkIlMjAlMkYlMkYlMjB3b3VsZG50JTIwd29yayU1Q24lN0QlNUNuJTVDbmYoKSU1Q25mKCklNUNuJTVDbiUyRiUyRiUyMGNvbnNvbGUubG9nKHJlc3RhcnRpbmdDb3VzT2YpJTIwJTJGJTJGJTIwd291bGQlMjB3b3JrJTIwYXMlMjB0aGUlMjBtdXRhdGlvbnMlMjB0byUyMGFyciUyMGFyZSUyMGltcG9ydGFudCUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTJDJTIybmFtZSUyMiUzQSUyMm15QnVuZGxlJTIyJTJDJTIyYW1kJTIyJTNBJTdCJTIyaWQlMjIlM0ElMjIlMjIlN0QlMkMlMjJnbG9iYWxzJTIyJTNBJTdCJTdEJTdEJTJDJTIyZXhhbXBsZSUyMiUzQW51bGwlN0Q=

Expected Behaviour

Executing the bundled output should yield the same result as executing the source.

The dead code detection should assume the same possibility for side effects in the prototype for natively declared array instances as it does for those declared with new Array().

Actual Behaviour

I assume it assumes we are accessing a property that doesn't exist (as it usually doesn't on arrays), which is very ambitious, but not save as illustrated in the repl above.

@lukastaegert
Copy link
Member

Yes, this is a known limitation that we assume built-ins have not been tampered with. One could argue, though, that with respect to future prototype features that are not yet known to rollup, missing prototype properties should be handled as unknown instead of undefined.

@lukastaegert
Copy link
Member

I created a PR to improve this with respect to handling future prototype methods gracefully: #4428

@maximilianMairinger
Copy link
Author

Looks great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants