mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
parent
1d865b9979
commit
ad49de35b3
@ -582,12 +582,19 @@ impl Actual {
|
|||||||
fn make_fn_ref(mut expr: FnExpr) -> Expr {
|
fn make_fn_ref(mut expr: FnExpr) -> Expr {
|
||||||
struct AwaitToYield;
|
struct AwaitToYield;
|
||||||
|
|
||||||
impl Fold<Function> for AwaitToYield {
|
macro_rules! noop {
|
||||||
|
($T:path) => {
|
||||||
|
impl Fold<$T> for AwaitToYield {
|
||||||
/// Don't recurse into function.
|
/// Don't recurse into function.
|
||||||
fn fold(&mut self, f: Function) -> Function {
|
fn fold(&mut self, f: $T) -> $T {
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
noop!(Function);
|
||||||
|
noop!(Constructor);
|
||||||
|
noop!(ArrowExpr);
|
||||||
|
|
||||||
impl Fold<Expr> for AwaitToYield {
|
impl Fold<Expr> for AwaitToYield {
|
||||||
fn fold(&mut self, expr: Expr) -> Expr {
|
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!(
|
test!(
|
||||||
::swc_ecma_parser::Syntax::default(),
|
::swc_ecma_parser::Syntax::default(),
|
||||||
|_| tr(),
|
|_| tr(),
|
||||||
|
@ -309,7 +309,9 @@ impl Fold<Expr> for Fixer {
|
|||||||
|
|
||||||
Expr::Bin(mut expr) => {
|
Expr::Bin(mut expr) => {
|
||||||
expr.right = match *expr.right {
|
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,
|
_ => expr.right,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user