Destructuring assignment prevents tree shaking of function with prototypes
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 26.3k
- Forks
- 1.8k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 20
Description
- Rollup Version: 2.33.3
- Operating System (or Browser): Firefox
- Node Version (if applicable): N/A
- Link to reproduction (IMPORTANT, read below): https://rollupjs.org/repl/?version=2.33.3&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmZ1bmN0aW9uJTIwRm9vJTIwKCklMjAlN0IlN0QlNUNuJTVDbkZvby5wcm90b3R5cGUuYmFyJTIwJTNEJTIwZnVuY3Rpb24lMjAoKSUyMCU3QiU3RCU1Q24lNUNuY29uc3QlMjBvYmolMjAlM0QlMjAlN0IlMjBGb28lMjQlM0ElMjBGb28lMjAlN0QlNUNuJTVDbmNvbnN0JTIwJTdCJTIwRm9vJTI0JTIwJTdEJTIwJTNEJTIwb2JqJTVDbiU1Q24lMkYlMkYlMjBFdmVyeXRoaW5nJTIwaXMlMjB0cmVlc2hha2VkJTIwaWYlMjB0aGUlMjBkZXN0cnVjdHVyaW5nJTIwZGVjbGFyYXRpb24lMjBpcyUyMHJlcGxhY2VkJTIwYnklM0ElNUNuJTJGJTJGY29uc3QlMjBGb28lMjQlMjAlM0QlMjBvYmouRm9vJTI0JTVDbiUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTJDJTIybmFtZSUyMiUzQSUyMm15QnVuZGxlJTIyJTJDJTIyYW1kJTIyJTNBJTdCJTIyaWQlMjIlM0ElMjIlMjIlN0QlMkMlMjJnbG9iYWxzJTIyJTNBJTdCJTdEJTdEJTJDJTIyZXhhbXBsZSUyMiUzQW51bGwlN0Q=
In this configuration:
function Foo () {}
Foo.prototype.bar = function () {}
const obj = { Foo$: Foo }
const { Foo$ } = obj
I can't figure out why "Foo" is not removed after tree-shaking. Using const Foo$ = obj.Foo$ or removing Foo.prototype.bar declaration fixes the issue.
Expected Behavior
In the example above, everything should be removed after tree-shaking
Actual Behavior
The function Foo and Foo.prototype.bar declarations are kept after thee-shaking
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Rollup REPL reproduction using the shown destructuring assignment and prototype property. Compare its output with the direct property assignment case, then trace the tree-shaking behavior; done means the unused Foo function and Foo.prototype.bar declarations are removed as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100