-
Notifications
You must be signed in to change notification settings - Fork 657
fix(rome_js_analyzer): precedence for useOptionalChain
#3277
Conversation
✅ Deploy Preview for rometools canceled.
|
crates/rome_js_analyze/src/analyzers/nursery/use_optional_chain.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure those are really false positive, it looks more like the fix is simply incorrectly removing the parenthesis: (new foo || {}).bar
should be replaced with (new foo)?.bar
, but the generated code action emits new foo?.bar
instead which then gets re-parsed as new (foo?.bar)
and results in a syntax error
f8fc203
to
f388693
Compare
Turns out that the issue was the precedence. If you check the MDN table the The absence of arguments yields a unique precedence just for this case, which was not tracked in our enum. I updated the code and it now works as @leops suggested. |
f388693
to
d77371b
Compare
d77371b
to
db4a06a
Compare
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
useOptionalChain
useOptionalChain
useOptionalChain
useOptionalChain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind testing if the formatter handles the precedence correctly and, if not, fix the parentheses setting in its own PR?
Summary
This PR fixes #3257
Test Plan
The PR add two new test cases