fix(es/codegen): Preserve more parens (#6268)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6266.
This commit is contained in:
Donny/강동윤 2022-10-27 12:02:56 +09:00 committed by GitHub
parent d2dc90bc69
commit c3184463f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,6 @@
function test(node) {
return (
// comment from the source code
(_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter((m) => !ts.isDecorator(m))
);
}

View File

@ -0,0 +1,6 @@
function test(node) {
return(// comment from the source code
(_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter(function(m) {
return !ts.isDecorator(m);
}));
}

View File

@ -2736,6 +2736,12 @@ where
}
}
Expr::Cond(e) => {
if self.has_leading_comment(&e.test) {
return true;
}
}
Expr::Seq(e) => {
if let Some(e) = e.exprs.first() {
if self.has_leading_comment(e) {
@ -2744,6 +2750,22 @@ where
}
}
Expr::Assign(e) => {
if let Some(cmt) = self.comments {
let lo = e.span.lo;
if cmt.has_leading(lo) {
return true;
}
}
if let Some(e) = e.left.as_expr() {
if self.has_leading_comment(e) {
return true;
}
}
}
_ => {}
}