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
fix(es/fixer): Preserve parens of optional chaining expressions #6164
Conversation
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.
swc-bump:
- swc_ecma_transforms_base
Pull request was converted to draft
@@ -577,6 +577,18 @@ impl VisitMut for Fixer<'_> { | |||
|
|||
_ => {} | |||
} | |||
|
|||
dbg!(&*n.obj); |
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.
cc @Austaras I think AST definition is wrong.
We can't store ParenExpr
in OptChainBase
. Any idea?
Should we add a variant to it?
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.
Maybe it should be Paren (OptChain (OptChainMember))
?
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.
It does not work.
global.a = null;
let foo = "PASS";
a?.b[(foo = "FAIL")];
console.log(foo);
this is a terser test case, and it should not be
global.a = null;
let foo = "PASS";
(a?.b)[(foo = "FAIL")];
console.log(foo);
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.
If a?.b[(foo = "FAIL")];
is the raw input, it should be OptChain(OptChainMember (Member))
while (a?.b)[(foo = "FAIL")]
should be Member(OptChain(OptChainMember))
, at least this is what babel is doing
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.
Thanks! I'm not sure if it's ideal, but we can avoid a breaking change for wasm plugin authors with that way 👍
@@ -242,7 +242,7 @@ let NATIVE_OS = "linux"; | |||
const navigator = globalThis.navigator; | |||
if (globalThis.Deno != null) { | |||
NATIVE_OS = Deno.build.os; | |||
} else if (navigator?.appVersion?.includes?.("Win") ?? false) { | |||
} else if ((navigator?.appVersion)?.includes?.("Win") ?? false) { |
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.
In this very specific case (foo?.bar)?.baz
, you can't actually observe the difference, because the chain is immediately made optional again.
Description:
Related issue: