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

optional chaining grouping bug #156

Closed
kzc opened this issue May 28, 2020 · 2 comments
Closed

optional chaining grouping bug #156

kzc opened this issue May 28, 2020 · 2 comments

Comments

@kzc
Copy link
Contributor

kzc commented May 28, 2020

An obscure corner of the spec as gleaned from estree/estree#204 ...

Given:

$ esbuild --version
0.4.2
$ cat optchain.js
let o=null;try{o=(o?.a).b||"FAIL";}catch(x){}console.log(o||"PASS");

Expected:

$ cat optchain.js | node-v14.3.0
PASS

Actual:

$ cat optchain.js | esbuild --minify | node-v14.3.0
FAIL
$ cat optchain.js | esbuild --minify
let o=null;try{o=o?.a.b||"FAIL"}catch(a){}console.log(o||"PASS");

Down-levelling will preserve the intent of the original parentheses however:

$ cat optchain.js | esbuild --target=es2019 --minify | node-v14.3.0
PASS
$ cat optchain.js | esbuild --target=es2019 --minify
let o=null;try{o=(o==null?void 0:o.a).b||"FAIL"}catch(a){}console.log(o||"PASS");
@evanw
Copy link
Owner

evanw commented May 28, 2020

Ah crap. Thanks so much for calling this out. I made sure the lowering worked in that case but forgot about pass-through. I like the idea in that thread of thinking of ?. as a normal infix operator, as well as . belonging to an optional chain. I'll figure out how to fix this.

@kzc
Copy link
Contributor Author

kzc commented May 28, 2020

It's interesting that there are as many ways to model optional chaining as there are estree contributors. No one would likely ever use parentheses in this context in real life code. Hmm... maybe it could be used as a sort of mid-expression assert.

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

2 participants