Skip to content

Commit 8ba0b68

Browse files
authored
fix: support using decl in for of stmt (#655)
1 parent 9a734c2 commit 8ba0b68

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/generation/generate.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ fn gen_using_decl<'a>(node: &UsingDecl<'a>, context: &mut Context<'a>) -> PrintI
14741474

14751475
items.extend(gen_var_declarators(node.into(), node.decls, context));
14761476

1477-
if context.config.semi_colons.is_true() {
1477+
if requires_semi_colon_for_var_or_using_decl(node.into(), context) {
14781478
items.push_sc(sc!(";"));
14791479
}
14801480

@@ -5343,22 +5343,22 @@ fn gen_var_decl<'a>(node: &VarDecl<'a>, context: &mut Context<'a>) -> PrintItems
53435343

53445344
items.extend(gen_var_declarators(node.into(), node.decls, context));
53455345

5346-
if requires_semi_colon(node, context) {
5346+
if requires_semi_colon_for_var_or_using_decl(node.into(), context) {
53475347
items.push_sc(sc!(";"));
53485348
}
53495349

5350-
return items;
5350+
items
5351+
}
53515352

5352-
fn requires_semi_colon(node: &VarDecl, context: &mut Context) -> bool {
5353-
let use_semi_colons = context.config.semi_colons.is_true();
5354-
use_semi_colons
5355-
&& match node.parent() {
5356-
Node::ForInStmt(node) => node.start() >= node.body.start(),
5357-
Node::ForOfStmt(node) => node.start() >= node.body.start(),
5358-
Node::ForStmt(node) => node.start() >= node.body.start(),
5359-
_ => use_semi_colons,
5360-
}
5361-
}
5353+
fn requires_semi_colon_for_var_or_using_decl(node: Node, context: &mut Context) -> bool {
5354+
let use_semi_colons = context.config.semi_colons.is_true();
5355+
use_semi_colons
5356+
&& match node.parent() {
5357+
Some(Node::ForInStmt(node)) => node.start() >= node.body.start(),
5358+
Some(Node::ForOfStmt(node)) => node.start() >= node.body.start(),
5359+
Some(Node::ForStmt(node)) => node.start() >= node.body.start(),
5360+
_ => use_semi_colons,
5361+
}
53625362
}
53635363

53645364
fn gen_var_declarators<'a>(parent: Node<'a>, decls: &[&'a VarDeclarator<'a>], context: &mut Context<'a>) -> PrintItems {

tests/specs/declarations/using/Using_All.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ function test() {
1010
using f = 2, g = 3, testingTheLimitOut = 4;
1111
}
1212

13+
for (using test of something) {
14+
}
15+
for (using test in something) {
16+
}
17+
1318
[expect]
1419
using a!: string;
1520
using b = 5;
@@ -25,6 +30,11 @@ function test() {
2530
testingTheLimitOut = 4;
2631
}
2732

33+
for (using test of something) {
34+
}
35+
for (using test in something) {
36+
}
37+
2838
== should not wrap within a variable declaration ==
2939
using t: Testing, testingThis: outALittleBit;
3040

0 commit comments

Comments
 (0)