mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
fix(es/codegen): Handle comments in binary expressions (#4817)
This commit is contained in:
parent
e770651698
commit
1db71cc3b3
12
crates/swc/tests/fixture/issues-4xxx/4816/1/input/.swcrc
Normal file
12
crates/swc/tests/fixture/issues-4xxx/4816/1/input/.swcrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript"
|
||||
},
|
||||
"preserveAllComments": true,
|
||||
"target": "es2017",
|
||||
"minify": {
|
||||
"compress": true
|
||||
}
|
||||
}
|
||||
}
|
23
crates/swc/tests/fixture/issues-4xxx/4816/1/input/index.js
Normal file
23
crates/swc/tests/fixture/issues-4xxx/4816/1/input/index.js
Normal 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
|
||||
}
|
15
crates/swc/tests/fixture/issues-4xxx/4816/1/output/index.js
Normal file
15
crates/swc/tests/fixture/issues-4xxx/4816/1/output/index.js
Normal 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
|
12
crates/swc/tests/fixture/issues-4xxx/4816/2/input/.swcrc
Normal file
12
crates/swc/tests/fixture/issues-4xxx/4816/2/input/.swcrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript"
|
||||
},
|
||||
"preserveAllComments": true,
|
||||
"target": "es2017",
|
||||
"minify": {
|
||||
"compress": true
|
||||
}
|
||||
}
|
||||
}
|
15
crates/swc/tests/fixture/issues-4xxx/4816/2/input/index.js
Normal file
15
crates/swc/tests/fixture/issues-4xxx/4816/2/input/index.js
Normal file
@ -0,0 +1,15 @@
|
||||
export function left() {
|
||||
return (
|
||||
// left binop
|
||||
check() || action(), foo()
|
||||
);
|
||||
}
|
||||
|
||||
export function right() {
|
||||
return (
|
||||
check() ||
|
||||
// right binop
|
||||
action(),
|
||||
foo()
|
||||
);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
export function left() {
|
||||
return(// left binop
|
||||
check() || action(), foo());
|
||||
}
|
||||
export function right() {
|
||||
return check() || // right binop
|
||||
action(), foo();
|
||||
}
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user