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

Make sure the initializer of hoisted variables is deoptimized #4149

Merged
merged 3 commits into from Jun 25, 2021

Conversation

lukastaegert
Copy link
Member

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:
Resolves #4147

Description

There was already a logic to deoptimize var variables that are defined in nested scopes. This logic deoptimized the value of such variables but forgot to also deoptimize the initializer of those variables. It also deoptimizes initializers when vars are deoptimized via treeshake.correctVarValueBeforeDeclaration.
While this is a bug fix, it may prove interesting to see if #4148 will offer a way to handle these things differently. This should not prevent release, however.

@github-actions
Copy link

github-actions bot commented Jun 25, 2021

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#gh-4147-deoptimize-hoisted-vars

or load it into the REPL:
https://rollupjs.org/repl/?pr=4149

@codecov
Copy link

codecov bot commented Jun 25, 2021

Codecov Report

Merging #4149 (15695cb) into master (6eaecf3) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4149   +/-   ##
=======================================
  Coverage   98.28%   98.28%           
=======================================
  Files         201      201           
  Lines        7116     7118    +2     
  Branches     2084     2084           
=======================================
+ Hits         6994     6996    +2     
  Misses         58       58           
  Partials       64       64           
Impacted Files Coverage Δ
src/ast/scopes/CatchScope.ts 100.00% <ø> (ø)
src/ast/nodes/Identifier.ts 100.00% <100.00%> (ø)
src/ast/scopes/BlockScope.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 6eaecf3...15695cb. Read the comment docs.

@lukastaegert lukastaegert force-pushed the gh-4147-deoptimize-hoisted-vars branch from 794de34 to 15695cb Compare June 25, 2021 12:54
@lukastaegert lukastaegert merged commit 6260def into master Jun 25, 2021
@lukastaegert lukastaegert deleted the gh-4147-deoptimize-hoisted-vars branch June 25, 2021 13:04
lukastaegert added a commit that referenced this pull request Jul 7, 2021
* Fix var/const/let variable use before declaration
* Also retains TDZ violations present in input
* Enabled by default when treeshake is active
* Low overhead - uses existing treeshaking simulated
  execution to mark declarations as reached

* successfully run tests from #4149
without treeshake.correctVarBeforeDeclaration

* Fix pattern handling

* Handle TDZ class access

* Improve field name

* Fix TDZ caching

* Only include entry point exports after first treeshaking pass

* No longer make TDZ var access a side effect but treat as unknown value

* Remove special logic for TDZ var assignments

* Improve self-reference in declaration handling

* Deprecate treeshake.correctVarValueBeforeDeclaration

* Make deprecation non-active until next major version

* Undeprecate correctVarValueBeforeDeclaration

* Fix deoptimization regression for call expressions

* Improve coverage

Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
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.

Deletes babel code, leading to broken while loops
1 participant