rollup / rollup/rollup

Destructuring assignment prevents tree shaking of function with prototypes

Open
#3,878 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
26.3k
Forks
1.8k
Avg merge
2d 11h
Merged PRs (30d)
20

Description

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.