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

wrong scope for destructuring catch leads to incorrect treeshake #4096

Closed
kzc opened this issue May 25, 2021 · 1 comment · Fixed by #4108
Closed

wrong scope for destructuring catch leads to incorrect treeshake #4096

kzc opened this issue May 25, 2021 · 1 comment · Fixed by #4108

Comments

@kzc
Copy link
Contributor

kzc commented May 25, 2021

  • Rollup Version: rollup v2.50.0
  • Operating System (or Browser): n/a
  • Node Version (if applicable): v16.1.0

Repro

$ cat destructuring-catch-scope.js 
let a = 1;         // mistakenly dropped
let def = "PASS2"; // mistakenly dropped
try {
    throw [ "FAIL2", "PASS1" ];
} catch ({ [a]: b, 3: d = def }) {
    let a = 0, def = "FAIL3";
    console.log(b, d);
}

Expected Behavior

$ cat destructuring-catch-scope.js | node
PASS1 PASS2

Actual Behavior

$ cat destructuring-catch-scope.js | rollup --silent
try {
    throw [ "FAIL2", "PASS1" ];
} catch ({ [a]: b, 3: d = def }) {
    let a = 0, def = "FAIL3";
    console.log(b, d);
}
$ cat destructuring-catch-scope.js | rollup --silent | node
[stdin]:3
} catch ({ [a]: b, 3: d = def }) {
                ^

ReferenceError: a is not defined
@lukastaegert
Copy link
Member

Good catch 🙄 Fix at #4108. That one will also fix the other catch scoping issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants