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

incorrect scope handling for catch argument with destructuring #1812

Closed
kzc opened this issue Nov 29, 2021 · 0 comments
Closed

incorrect scope handling for catch argument with destructuring #1812

kzc opened this issue Nov 29, 2021 · 0 comments

Comments

@kzc
Copy link
Contributor

kzc commented Nov 29, 2021

Mentioned in #1305 (comment)

$ 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:

$ cat destructuring-catch-scope.js | node
PASS1 PASS2
$ cat destructuring-catch-scope.js | rollup --silent -p terser | node
PASS1 PASS2

Using --bundle with e1bb432:

$ esbuild --version
0.14.0

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

ReferenceError: a is not defined

esbuild minify:

$ cat destructuring-catch-scope.js | esbuild --minify | node
[stdin]:1
let a=1,def="PASS2";try{throw["FAIL2","PASS1"]}catch({[l]:e,3:t=o}){let l=0,o="FAIL3";console.log(e,t)}
                                                          ^

ReferenceError: l is not defined
@evanw evanw closed this as completed in 4893c32 Dec 3, 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

No branches or pull requests

1 participant