Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - regenerator: allow nested finally block #601

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
regenerator: handle for of
kdy1 committed Jan 22, 2020
commit 29620c7e6c37b070cda2dbfce5bc28758b61bb76
85 changes: 83 additions & 2 deletions ecmascript/transforms/src/compat/es2015/regenerator/case.rs
Original file line number Diff line number Diff line change
@@ -99,7 +99,12 @@ impl CaseHandler<'_> {
.into_iter()
.map(|entry: TryEntry| {
let this_loc_value = entry.first_loc;
assert!(this_loc_value.stmt_index >= last_loc_value);
assert!(
this_loc_value.stmt_index >= last_loc_value,
"this_loc_value = {:?}; last_loc_value = {};",
this_loc_value,
last_loc_value
);
last_loc_value = this_loc_value.stmt_index;

let ce = entry.catch_entry;
@@ -1343,7 +1348,83 @@ impl CaseHandler<'_> {
self.mark(after);
}

Stmt::Decl(_) | Stmt::ForOf(_) => self.emit(s),
Stmt::ForOf(s) => {
let body = s.body;

let head = self.loc();
let after = self.loc();

let key_iter_next_fn = self.make_var();

let right = s.right.map(|e| self.explode_expr(e, false));
self.emit_assign(
key_iter_next_fn.clone(),
CallExpr {
span: DUMMY_SP,
callee: member_expr!(DUMMY_SP, regeneratorRuntime.keys).as_callee(),
args: vec![right.as_arg()],
type_args: Default::default(),
}
.into(),
);

let head = self.mark(head);

let key_info_tmp_var = self.make_var();

self.jump_if(
box AssignExpr {
span: DUMMY_SP,
op: op!("="),
left: PatOrExpr::Expr(box key_info_tmp_var.clone().into()),
right: box CallExpr {
span: DUMMY_SP,
callee: key_iter_next_fn.as_callee(),
args: vec![],
type_args: Default::default(),
}
.into(),
}
.member(quote_ident!("done")),
after,
);

{
let right = box key_info_tmp_var.clone().member(quote_ident!("value"));
match s.left {
VarDeclOrPat::VarDecl(var) => unreachable!(
"VarDeclaration in for-in statement must be hoisted: {:?}",
var
),
VarDeclOrPat::Pat(pat) => self.emit(
AssignExpr {
span: DUMMY_SP,
op: op!("="),
left: PatOrExpr::Pat(box pat),
right,
}
.into_stmt(),
),
}
}

self.with_entry(
Entry::Loop {
break_loc: after,
continue_loc: head,
label,
},
|folder| {
folder.explode_stmt(*body, None);
},
);

self.jump(head);

self.mark(after);
}

Stmt::Decl(_) => self.emit(s),
}
}
}
3 changes: 2 additions & 1 deletion ecmascript/transforms/tests/es2015_regenerator.rs
Original file line number Diff line number Diff line change
@@ -1002,8 +1002,9 @@ test_exec!(
syntax(),
|_| chain!(async_to_generator(), tr(Default::default())),
issue_600_3,
"async function foo() {
"function* foo() {
for (let a of b) {
yield a
}
}"
);