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

Correctly handle catch declarations #4108

Merged
merged 2 commits into from May 28, 2021
Merged

Conversation

lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented May 28, 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:
Resolves #4096
Resolves #4106

Description

There was a scoping issue in catch scopes that could lead to incorrect variable associations, see the linked issues. The implemented logic now works like this:

  • The body of a catch clause now receives a block scope so that block scoped declarations do not seep into surrounding scopes, including the parameter scope
  • Hoisted declarations inside the catch clause that do not match a parameter name will be hoisted to the surrounding scope (as before)
  • Hoisted declarations that DO match a parameter will instead be associated with the parameter and are not hoisted to the outside (this is new and indeed correct)

@github-actions
Copy link

github-actions bot commented May 28, 2021

Thank you for your contribution! ❤️

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

npm install rollup/rollup#gh-4096-catch-block-scoping

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

@codecov
Copy link

codecov bot commented May 28, 2021

Codecov Report

Merging #4108 (c5bae30) into master (8308279) will decrease coverage by 0.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4108      +/-   ##
==========================================
- Coverage   98.02%   98.01%   -0.02%     
==========================================
  Files         201      201              
  Lines        7038     7040       +2     
  Branches     2064     2065       +1     
==========================================
+ Hits         6899     6900       +1     
  Misses         66       66              
- Partials       73       74       +1     
Impacted Files Coverage Δ
src/ast/nodes/CatchClause.ts 83.33% <75.00%> (-16.67%) ⬇️
src/ast/scopes/CatchScope.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 8308279...c5bae30. Read the comment docs.

@lukastaegert lukastaegert merged commit 700b2e0 into master May 28, 2021
@lukastaegert lukastaegert deleted the gh-4096-catch-block-scoping branch May 28, 2021 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant