mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
fix(es/fixer): Fix handling of yield
and await
(#5533)
This commit is contained in:
parent
1bdf6a7385
commit
7394deef42
9
crates/swc/tests/fixture/issues-5xxx/5530/input/.swcrc
Normal file
9
crates/swc/tests/fixture/issues-5xxx/5530/input/.swcrc
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript"
|
||||
},
|
||||
"target": "es2022"
|
||||
},
|
||||
"isModule": true
|
||||
}
|
22
crates/swc/tests/fixture/issues-5xxx/5530/input/index.js
Normal file
22
crates/swc/tests/fixture/issues-5xxx/5530/input/index.js
Normal file
@ -0,0 +1,22 @@
|
||||
async function* level1() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
|
||||
async function* level2() {
|
||||
yield* (0, level1());
|
||||
}
|
||||
|
||||
async function* foo() {
|
||||
yield (foo, bar);
|
||||
await (foo, bar);
|
||||
yield* (0, level1());
|
||||
await (0, level1());
|
||||
yield (foo ? bar : baz);
|
||||
await (foo ? bar : baz);
|
||||
yield (++foo);
|
||||
await (++foo);
|
||||
yield (!foo);
|
||||
await (!foo);
|
||||
}
|
20
crates/swc/tests/fixture/issues-5xxx/5530/output/index.js
Normal file
20
crates/swc/tests/fixture/issues-5xxx/5530/output/index.js
Normal file
@ -0,0 +1,20 @@
|
||||
async function* level1() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
async function* level2() {
|
||||
yield* (0, level1());
|
||||
}
|
||||
async function* foo() {
|
||||
yield (foo, bar);
|
||||
await (foo, bar);
|
||||
yield* (0, level1());
|
||||
await (0, level1());
|
||||
yield foo ? bar : baz;
|
||||
await (foo ? bar : baz);
|
||||
yield ++foo;
|
||||
await ++foo;
|
||||
yield !foo;
|
||||
await !foo;
|
||||
}
|
@ -194,15 +194,18 @@ impl VisitMut for Fixer<'_> {
|
||||
self.ctx = old;
|
||||
|
||||
match &*expr.arg {
|
||||
Expr::Cond(..)
|
||||
| Expr::Assign(..)
|
||||
| Expr::Bin(..)
|
||||
| Expr::Unary(..)
|
||||
| Expr::Update(..) => self.wrap(&mut expr.arg),
|
||||
Expr::Cond(..) | Expr::Assign(..) | Expr::Bin(..) => self.wrap(&mut expr.arg),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_yield_expr(&mut self, expr: &mut YieldExpr) {
|
||||
let old = self.ctx;
|
||||
self.ctx = Context::ForcedExpr;
|
||||
expr.arg.visit_mut_with(self);
|
||||
self.ctx = old;
|
||||
}
|
||||
|
||||
fn visit_mut_bin_expr(&mut self, expr: &mut BinExpr) {
|
||||
expr.left.visit_mut_with(self);
|
||||
let ctx = self.ctx;
|
||||
|
Loading…
Reference in New Issue
Block a user