Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/generation/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions tests/specs/statements/forOfStatement/ForOfStatement_All.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Loading