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

Extract hoisted variables from dead branches #3752

Merged
merged 2 commits into from Aug 28, 2020

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 #3749

Description

When attempting to fix #3749, I found that there are quite a few more ways of having variable declarations in dead branches that would cause Rollup to crash. This should fix them all by gathering all hoisted variables in dead branches and rendering them explicitly as a separate var declaration.

While doing this I also learned that in strict mode, function declarations are not hoisted across block scope boundaries; this made things quite a bit easier. This will make code more concise while also fixing the original issue.

@rollup-bot
Copy link
Collaborator

rollup-bot commented Aug 28, 2020

Thank you for your contribution! ❤️

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

npm install rollup/rollup#gh-3749-unused-for-loop-var-declaration

or load it into the REPL:
https://rollupjs.org/repl/?circleci=12749

@codecov
Copy link

codecov bot commented Aug 28, 2020

Codecov Report

Merging #3752 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3752      +/-   ##
==========================================
+ Coverage   96.99%   97.02%   +0.03%     
==========================================
  Files         184      185       +1     
  Lines        6454     6461       +7     
  Branches     1873     1868       -5     
==========================================
+ Hits         6260     6269       +9     
+ Misses        103      101       -2     
  Partials       91       91              
Impacted Files Coverage Δ
src/ast/nodes/VariableDeclarator.ts 100.00% <ø> (ø)
src/ast/scopes/CatchScope.ts 100.00% <ø> (ø)
src/ast/scopes/Scope.ts 83.33% <ø> (+6.41%) ⬆️
src/ast/nodes/Identifier.ts 100.00% <100.00%> (ø)
src/ast/nodes/IfStatement.ts 100.00% <100.00%> (ø)
src/ast/scopes/BlockScope.ts 100.00% <100.00%> (+20.00%) ⬆️
src/ast/scopes/TrackingScope.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 7bc7c90...aa8e252. Read the comment docs.

@lukastaegert lukastaegert force-pushed the gh-3749-unused-for-loop-var-declaration branch from e137260 to de108f0 Compare August 28, 2020 14:56
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.

Crash with "TypeError: Cannot read property 'render' of null"
2 participants