mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 00:23:10 +03:00
fix(es/transforms/compat): Fix regenerator pass for yield* expressions (#1580)
swc_ecma_transforms_compat: - `regenerator`: Fix delegating yield expressions.
This commit is contained in:
parent
60ad0df3f5
commit
efa7a9af78
@ -710,6 +710,13 @@ impl CaseHandler<'_> {
|
||||
|
||||
if arg.is_some() && e.delegate {
|
||||
let result = self.make_var();
|
||||
let name = match &result {
|
||||
Expr::Member(m) => match &*m.prop {
|
||||
Expr::Ident(id) if !m.computed => id.sym.clone(),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let ret = ReturnStmt {
|
||||
// Preserve span
|
||||
@ -723,7 +730,13 @@ impl CaseHandler<'_> {
|
||||
.as_callee(),
|
||||
args: vec![
|
||||
arg.unwrap().as_arg(),
|
||||
result.clone().as_arg(),
|
||||
Lit::Str(Str {
|
||||
span: DUMMY_SP,
|
||||
value: name,
|
||||
has_escape: false,
|
||||
kind: Default::default(),
|
||||
})
|
||||
.as_arg(),
|
||||
after.to_stmt_index().as_arg(),
|
||||
],
|
||||
type_args: Default::default(),
|
||||
|
@ -1015,7 +1015,7 @@ export function myGenerator() {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
], _ctx.t0, 1);
|
||||
], \"t0\", 1);
|
||||
case 1:
|
||||
case 'end':
|
||||
return _ctx.stop();
|
||||
@ -1025,6 +1025,21 @@ export function myGenerator() {
|
||||
"
|
||||
);
|
||||
|
||||
test_exec!(
|
||||
syntax(),
|
||||
|_| es2015::regenerator(Mark::fresh(Mark::root())),
|
||||
delegate_context,
|
||||
"function* a() {
|
||||
yield 5;
|
||||
return 7;
|
||||
}
|
||||
function* b() {
|
||||
let x = yield* a();
|
||||
yield (x + 1);
|
||||
}
|
||||
expect([...b()]).toEqual([5, 8]);"
|
||||
);
|
||||
|
||||
test_exec!(
|
||||
syntax(),
|
||||
|_| es2015::regenerator(Mark::fresh(Mark::root())),
|
||||
|
@ -4499,7 +4499,7 @@ function myGenerator() {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
], _ctx.t0, 1);
|
||||
], \"t0\", 1);
|
||||
case 1:
|
||||
case 'end':
|
||||
return _ctx.stop();
|
||||
|
Loading…
Reference in New Issue
Block a user