From 1e3583df5b919a188c64221a657a2beaef0cb4c6 Mon Sep 17 00:00:00 2001 From: Yazan AbdAl-Rahman Date: Wed, 31 Jul 2024 22:10:29 +0300 Subject: [PATCH] fix: prevent prefix semicolon insertion for increment and decrement (#648) --- src/generation/generate.rs | 3 ++ ...ExpressionStatement_SemiColonInsertion.txt | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/generation/generate.rs b/src/generation/generate.rs index 688e6bd3..afcf1229 100644 --- a/src/generation/generate.rs +++ b/src/generation/generate.rs @@ -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(); } diff --git a/tests/specs/statements/expressionStatement/ExpressionStatement_SemiColonInsertion.txt b/tests/specs/statements/expressionStatement/ExpressionStatement_SemiColonInsertion.txt index bc1c7cce..d97f7813 100644 --- a/tests/specs/statements/expressionStatement/ExpressionStatement_SemiColonInsertion.txt +++ b/tests/specs/statements/expressionStatement/ExpressionStatement_SemiColonInsertion.txt @@ -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