mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
parent
1d865b9979
commit
ad49de35b3
@ -582,12 +582,19 @@ impl Actual {
|
||||
fn make_fn_ref(mut expr: FnExpr) -> Expr {
|
||||
struct AwaitToYield;
|
||||
|
||||
impl Fold<Function> for AwaitToYield {
|
||||
/// Don't recurse into function.
|
||||
fn fold(&mut self, f: Function) -> Function {
|
||||
f
|
||||
}
|
||||
macro_rules! noop {
|
||||
($T:path) => {
|
||||
impl Fold<$T> for AwaitToYield {
|
||||
/// Don't recurse into function.
|
||||
fn fold(&mut self, f: $T) -> $T {
|
||||
f
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
noop!(Function);
|
||||
noop!(Constructor);
|
||||
noop!(ArrowExpr);
|
||||
|
||||
impl Fold<Expr> for AwaitToYield {
|
||||
fn fold(&mut self, expr: Expr) -> Expr {
|
||||
|
@ -27,6 +27,28 @@ fn tr() -> impl Fold<Module> {
|
||||
)
|
||||
}
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| tr(),
|
||||
issue_216,
|
||||
r#"
|
||||
async function foo(bar) {
|
||||
bar && await bar();
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
function _foo() {
|
||||
_foo = _asyncToGenerator(function*(bar) {
|
||||
bar && (yield bar());
|
||||
});
|
||||
return _foo.apply(this, arguments);
|
||||
}
|
||||
function foo(bar) {
|
||||
return _foo.apply(this, arguments);
|
||||
}
|
||||
"#
|
||||
);
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|_| tr(),
|
||||
|
@ -309,7 +309,9 @@ impl Fold<Expr> for Fixer {
|
||||
|
||||
Expr::Bin(mut expr) => {
|
||||
expr.right = match *expr.right {
|
||||
e @ Expr::Assign(..) | e @ Expr::Seq(..) => box e.wrap_with_paren(),
|
||||
e @ Expr::Assign(..) | e @ Expr::Seq(..) | e @ Expr::Yield(..) => {
|
||||
box e.wrap_with_paren()
|
||||
}
|
||||
_ => expr.right,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user