fix(es/fixer): Fix handling of yield and await (#5533)

This commit is contained in:
magic-akari 2022-08-18 02:28:37 +08:00 committed by GitHub
parent 1bdf6a7385
commit 7394deef42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 5 deletions

View File

@ -0,0 +1,9 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"target": "es2022"
},
"isModule": true
}

View 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);
}

View 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;
}

View File

@ -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;