Skip to content

Commit 3404916

Browse files
committed
fixup: handle for-of/in lvalues, labels
1 parent 1fdc2ad commit 3404916

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/async-rewriter2/src/async-writer-babel.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ describe('AsyncWriter', function () {
477477
expect(implicitlyAsyncFn).to.have.callCount(10);
478478
});
479479

480-
it.skip('can use for loops as weird assignments (sync)', async function () {
480+
it('can use for loops as weird assignments (sync)', async function () {
481481
const obj = { foo: null };
482482
implicitlyAsyncFn.resolves(obj);
483483
await runTranspiledCode(
@@ -487,7 +487,7 @@ describe('AsyncWriter', function () {
487487
expect(obj.foo).to.equal('bar');
488488
});
489489

490-
it.skip('can use for loops as weird assignments (async)', async function () {
490+
it('can use for loops as weird assignments (async)', async function () {
491491
const obj = { foo: null };
492492
implicitlyAsyncFn.resolves(obj);
493493
await runTranspiledCode(

packages/async-rewriter3/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{borrow::Borrow, collections::VecDeque, fmt::Debug};
22
use wasm_bindgen::prelude::*;
3-
use rslint_parser::{ast::{ArrowExpr, AssignExpr, CallExpr, ClassDecl, Constructor, Expr, ExprOrBlock, ExprStmt, FnDecl, FnExpr, GroupingExpr, Literal, Method, NameRef, ObjectPatternProp, ParameterList, Pattern, PropName, ReturnStmt, ThisExpr, UnaryExpr, VarDecl}, parse_text, AstNode, SyntaxKind, SyntaxNode, TextSize};
3+
use rslint_parser::{ast::{ArrowExpr, AssignExpr, BreakStmt, CallExpr, ClassDecl, Constructor, ContinueStmt, Expr, ExprOrBlock, ExprStmt, FnDecl, FnExpr, ForInStmt, ForOfStmt, ForStmtInit, GroupingExpr, Literal, Method, NameRef, ObjectPatternProp, ParameterList, Pattern, PropName, ReturnStmt, ThisExpr, UnaryExpr, VarDecl}, parse_text, AstNode, SyntaxKind, SyntaxNode, TextSize};
44

55
#[derive(Debug)]
66
enum InsertionText {
@@ -378,7 +378,17 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
378378
(is_unary_rhs && !is_typeof_rhs);
379379
let is_argument_default_value = ParameterList::can_cast(as_expr.syntax().parent().unwrap().parent().unwrap().kind());
380380
let is_literal = Literal::can_cast(as_expr.syntax().kind());
381-
let wants_implicit_await_wrapper = !is_lhs_of_assign_expr && !is_argument_default_value && !is_eval_this_super_reference && !is_literal;
381+
let is_label_in_continue_or_break = is_name_ref(as_expr.syntax(), None) &&
382+
ContinueStmt::can_cast(as_expr.syntax().parent().unwrap().kind()) || BreakStmt::can_cast(as_expr.syntax().parent().unwrap().kind());
383+
let is_for_in_of_lvalue =
384+
ForStmtInit::can_cast(as_expr.syntax().parent().unwrap().kind());
385+
let wants_implicit_await_wrapper =
386+
!is_lhs_of_assign_expr &&
387+
!is_argument_default_value &&
388+
!is_eval_this_super_reference &&
389+
!is_literal &&
390+
!is_label_in_continue_or_break &&
391+
!is_for_in_of_lvalue;
382392

383393
if is_named_typeof_rhs {
384394
insertions.push_back(Insertion::new_dynamic(as_expr.syntax().parent().unwrap().text_range().start(), [

0 commit comments

Comments
 (0)