Skip to content

Commit

Permalink
fix: prevent prefix semicolon insertion for increment and decrement (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yazan-abdalrahman authored Jul 31, 2024
1 parent f0fde1a commit 1e3583d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/generation/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4688,6 +4688,9 @@ fn gen_expr_stmt<'a>(stmt: &ExprStmt<'a>, context: &mut Context<'a>) -> PrintIte
for item in PrintItemsIterator::new(path) {
match item {
PrintItem::String(value) => {
if value.text.starts_with("++") || value.text.starts_with("--") {
return Some(false); // don't need to add for increment/decrement
}
if let Some(c) = value.text.chars().next() {
return utils::is_prefix_semi_colon_insertion_char(c).into();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,31 @@

[expect]
;[1, 2, 3].forEach(bar)

== shouldn't insert semi-colons at the start of lines beginning with increment ==
let x = 0
++x

[expect]
let x = 0
++x

== shouldn't insert semi-colons at the start of lines beginning with decrement ==
let x = 0
--x

[expect]
let x = 0
--x

== should insert semi-colons at the start of lines beginning with a single plus operator ==
+5

[expect]
;+5

== should insert semi-colons at the start of lines beginning with with a single subtract operator ==
-5

[expect]
;-5

0 comments on commit 1e3583d

Please sign in to comment.