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

implement --treeshake.propertyReadSideEffects=always to handle getters with side effects #3985

Merged
merged 1 commit into from
Mar 9, 2021
Merged

implement --treeshake.propertyReadSideEffects=always to handle getters with side effects #3985

merged 1 commit into from
Mar 9, 2021

Conversation

kzc
Copy link
Contributor

@kzc kzc commented Mar 4, 2021

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

#2219
#3234
#3974
#3984

Description

Rollup does not correctly handle code dealing with getters with side effects when treeshake is enabled (the default setting). To address this shortcoming, this PR adds an 'always' setting to treeshake.propertyReadSideEffects first proposed in #3234 (comment).

@codecov
Copy link

codecov bot commented Mar 4, 2021

Codecov Report

Merging #3985 (042f6f0) into master (a12ec5b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3985   +/-   ##
=======================================
  Coverage   97.21%   97.21%           
=======================================
  Files         191      191           
  Lines        6709     6712    +3     
  Branches     1962     1963    +1     
=======================================
+ Hits         6522     6525    +3     
  Misses         99       99           
  Partials       88       88           
Impacted Files Coverage Δ
src/ast/nodes/MemberExpression.ts 98.37% <100.00%> (+0.01%) ⬆️
src/ast/nodes/Property.ts 92.45% <100.00%> (+0.14%) ⬆️
src/utils/options/normalizeInputOptions.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a12ec5b...042f6f0. Read the comment docs.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks a lot. Just one comment regarding the wording.

CLI: `--treeshake.propertyReadSideEffects`/`--no-treeshake.propertyReadSideEffects`<br>
Default: `true`

If `true`, only retain property reads that are determined to be needed. Note: this setting assumes that all getters are side effect free.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat confusing and also not true, we do not assume all getters are side-effect free. true means retain property reads that Rollup can resolve to have side-effects.

Suggested change
If `true`, only retain property reads that are determined to be needed. Note: this setting assumes that all getters are side effect free.
If `true`, retain unused property reads that Rollup can determine to have side-effects. This includes accessing properties of `null` or `undefined` or triggering explicit getters via property access. Note that this does not cover destructuring assignment or getters on objects passed as function parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording was changed as requested. I struggled to describe this option because of the known getter issues.

@lukastaegert lukastaegert merged commit 5ca7216 into rollup:master Mar 9, 2021
@kzc kzc deleted the propertyReadSideEffects-always branch March 9, 2021 06:36
This was referenced Mar 9, 2021
This was referenced Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants