Skip to content

Commit c7a4555

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

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
@@ -444,7 +444,7 @@ describe('AsyncWriter', function () {
444444
expect(implicitlyAsyncFn).to.have.callCount(10);
445445
});
446446

447-
it.skip('can use for loops as weird assignments (sync)', async function () {
447+
it('can use for loops as weird assignments (sync)', async function () {
448448
const obj = { foo: null };
449449
implicitlyAsyncFn.resolves(obj);
450450
await runTranspiledCode(
@@ -454,7 +454,7 @@ describe('AsyncWriter', function () {
454454
expect(obj.foo).to.equal('bar');
455455
});
456456

457-
it.skip('can use for loops as weird assignments (async)', async function () {
457+
it('can use for loops as weird assignments (async)', async function () {
458458
const obj = { foo: null };
459459
implicitlyAsyncFn.resolves(obj);
460460
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)