fix(es/codegen): Handle comments in binary expressions (#4817)

This commit is contained in:
Sander Mathijs van Veen 2022-05-27 07:57:24 +02:00 committed by GitHub
parent e770651698
commit 1db71cc3b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"preserveAllComments": true,
"target": "es2017",
"minify": {
"compress": true
}
}
}

View File

@ -0,0 +1,23 @@
export function left() {
// left binop
if (!check()) action();
return foo();
}
export function right() {
if (!check())
// right binop
action();
return foo();
}
export function between() {
if (!check()) action();
// between
return foo();
}
export function end() {
if (!check()) action();
return foo(); // end
}

View File

@ -0,0 +1,15 @@
export function left() {
return(// left binop
check() || action(), foo());
}
export function right() {
return check() || // right binop
action(), foo();
}
export function between() {
// between
return check() || action(), foo();
}
export function end() {
return check() || action(), foo();
} // end

View File

@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"preserveAllComments": true,
"target": "es2017",
"minify": {
"compress": true
}
}
}

View File

@ -0,0 +1,15 @@
export function left() {
return (
// left binop
check() || action(), foo()
);
}
export function right() {
return (
check() ||
// right binop
action(),
foo()
);
}

View File

@ -0,0 +1,8 @@
export function left() {
return(// left binop
check() || action(), foo());
}
export function right() {
return check() || // right binop
action(), foo();
}

View File

@ -2706,6 +2706,12 @@ where
}
}
Expr::Bin(e) => {
if self.has_leading_comment(&e.left) {
return true;
}
}
Expr::Seq(e) => {
if let Some(e) = e.exprs.first() {
if self.has_leading_comment(e) {