diff --git a/src/generation/generate.rs b/src/generation/generate.rs index 7fb3a332..b66fd839 100644 --- a/src/generation/generate.rs +++ b/src/generation/generate.rs @@ -5137,12 +5137,13 @@ fn gen_for_of_stmt<'a>(node: &ForOfStmt<'a>, context: &mut Context<'a>) -> Print items.push_info(start_header_ln); items.push_info(start_header_lsil); items.push_sc(sc!("for")); - if context.config.for_of_statement_space_after_for_keyword { - items.push_space(); - } if node.is_await() { // todo: generate comments around await token range - items.push_sc(sc!("await ")); + items.push_space(); + items.push_sc(sc!("await")); + } + if context.config.for_of_statement_space_after_for_keyword { + items.push_space(); } let inner_header_range = SourceRange::new(node.left.start(), node.right.end()); items.extend(gen_node_in_parens( diff --git a/tests/specs/statements/forOfStatement/ForOfStatement_All.txt b/tests/specs/statements/forOfStatement/ForOfStatement_All.txt index 0e598ab6..1a96257c 100644 --- a/tests/specs/statements/forOfStatement/ForOfStatement_All.txt +++ b/tests/specs/statements/forOfStatement/ForOfStatement_All.txt @@ -48,6 +48,26 @@ for await (const t of test) { for await (const t of test) { } +== should format for await with empty body == +for await (const x of arr); + +[expect] +for await (const x of arr); + +== should format for await with binding identifier inside async function == +async function foo() { + for await (num of asyncIterable) { + console.log(num); + } +} + +[expect] +async function foo() { + for await (num of asyncIterable) { + console.log(num); + } +} + == should print a nested variable declaration with semi-colon == for (const t of test) { const u = 5; diff --git a/tests/specs/statements/forOfStatement/ForOfStatement_SpaceAfterForKeyword_False.txt b/tests/specs/statements/forOfStatement/ForOfStatement_SpaceAfterForKeyword_False.txt index 597b0ed0..a82a110b 100644 --- a/tests/specs/statements/forOfStatement/ForOfStatement_SpaceAfterForKeyword_False.txt +++ b/tests/specs/statements/forOfStatement/ForOfStatement_SpaceAfterForKeyword_False.txt @@ -10,3 +10,33 @@ for(const t of test) { a; b; } + +== should keep space between `for` and `await` (issue #692) == +for await (const t of test) { + a; +} + +[expect] +for await(const t of test) { + a; +} + +== should handle for await with binding identifier == +async function foo() { + for await (num of asyncIterable) { + console.log(num); + } +} + +[expect] +async function foo() { + for await(num of asyncIterable) { + console.log(num); + } +} + +== should handle for await with empty body == +for await (const x of arr); + +[expect] +for await(const x of arr);