Skip to content

Commit 8c39527

Browse files
committed
fix: keep space between 'for' and 'await' regardless of spaceAfterForKeyword (#692)
`gen_for_of_stmt` emitted the configured space between the `for` keyword and the next token *before* the `await` marker, then appended the literal `"await "`. With `forOfStatement.spaceAfterForKeyword: false` that produced `forawait (...)`, which is not valid syntax. Always insert the space between `for` and `await`, and let the config flag control the space between the keyword sequence and the open paren: - spaceAfterForKeyword: true -> 'for await (...)' / 'for (...)' - spaceAfterForKeyword: false -> 'for await(...)' / 'for(...)'
1 parent f7dd1f3 commit 8c39527

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/generation/generate.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,12 +5137,13 @@ fn gen_for_of_stmt<'a>(node: &ForOfStmt<'a>, context: &mut Context<'a>) -> Print
51375137
items.push_info(start_header_ln);
51385138
items.push_info(start_header_lsil);
51395139
items.push_sc(sc!("for"));
5140-
if context.config.for_of_statement_space_after_for_keyword {
5141-
items.push_space();
5142-
}
51435140
if node.is_await() {
51445141
// todo: generate comments around await token range
5145-
items.push_sc(sc!("await "));
5142+
items.push_space();
5143+
items.push_sc(sc!("await"));
5144+
}
5145+
if context.config.for_of_statement_space_after_for_keyword {
5146+
items.push_space();
51465147
}
51475148
let inner_header_range = SourceRange::new(node.left.start(), node.right.end());
51485149
items.extend(gen_node_in_parens(

tests/specs/statements/forOfStatement/ForOfStatement_SpaceAfterForKeyword_False.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ for(const t of test) {
1010
a;
1111
b;
1212
}
13+
14+
== should keep space between `for` and `await` (issue #692) ==
15+
for await (const t of test) {
16+
a;
17+
}
18+
19+
[expect]
20+
for await(const t of test) {
21+
a;
22+
}

0 commit comments

Comments
 (0)