Skip to content

Commit 1e3583d

Browse files
fix: prevent prefix semicolon insertion for increment and decrement (#648)
1 parent f0fde1a commit 1e3583d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/generation/generate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,6 +4688,9 @@ fn gen_expr_stmt<'a>(stmt: &ExprStmt<'a>, context: &mut Context<'a>) -> PrintIte
46884688
for item in PrintItemsIterator::new(path) {
46894689
match item {
46904690
PrintItem::String(value) => {
4691+
if value.text.starts_with("++") || value.text.starts_with("--") {
4692+
return Some(false); // don't need to add for increment/decrement
4693+
}
46914694
if let Some(c) = value.text.chars().next() {
46924695
return utils::is_prefix_semi_colon_insertion_char(c).into();
46934696
}

tests/specs/statements/expressionStatement/ExpressionStatement_SemiColonInsertion.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,31 @@
2222

2323
[expect]
2424
;[1, 2, 3].forEach(bar)
25+
26+
== shouldn't insert semi-colons at the start of lines beginning with increment ==
27+
let x = 0
28+
++x
29+
30+
[expect]
31+
let x = 0
32+
++x
33+
34+
== shouldn't insert semi-colons at the start of lines beginning with decrement ==
35+
let x = 0
36+
--x
37+
38+
[expect]
39+
let x = 0
40+
--x
41+
42+
== should insert semi-colons at the start of lines beginning with a single plus operator ==
43+
+5
44+
45+
[expect]
46+
;+5
47+
48+
== should insert semi-colons at the start of lines beginning with with a single subtract operator ==
49+
-5
50+
51+
[expect]
52+
;-5

0 commit comments

Comments
 (0)