Do not make Object.defineProperty/ies a side effect by default #4492
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
This was spawned from the same discussion https://twitter.com/pschroen/status/1522269915864256512?s=20&t=8igcqT2KuKkLKgGP3hjvVA as #4489 and will improve tree-shaking by only considering
Object.defineProperty
andObject.defineProperties
side effects if the target object is used. Their presence will still deoptimize the object in question, though.This is not entirely correct in so far as those two functions can throw e.g. when incorrect parameters are used ore when try to redefine a non-configurable property. I think this is acceptable as when this is actually critical, it will likely be wrapped in a try-catch, in which case Rollup will deoptimize and include the statement anyway.
https://rollupjs.org/repl/?pr=4492&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMGNvbnN0JTIwZm9vJTIwJTNEJTIwJTdCJTdEJTNCJTVDbiUyRiUyRiUyMFRoaXMlMjB3aWxsJTIwYmUlMjBpbmNsdWRlZCUyMGJlY2F1c2UlMjBmb28lMjBpcyUyMGV4cG9zZWQlNUNuT2JqZWN0LmRlZmluZVByb3BlcnR5KGZvbyUyQyUyMCdmb28nJTJDJTIwJTdCdmFsdWUlM0ElMjB0cnVlJTdEKSUzQiU1Q25PYmplY3QuZGVmaW5lUHJvcGVydGllcyhmb28lMkMlMjAlN0IlMjBiYXIlM0ElMjAlN0J2YWx1ZSUzQSUyMHRydWU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