From 52c73ceae4fd8964703302be44bec637cba85e19 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Sat, 7 Mar 2026 23:20:50 +0000 Subject: [PATCH] Extract inner expression from parenthesized conditions --- crates/bough-core/src/language/javascript.rs | 7 ++++++- crates/bough-core/src/mutation.rs | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/bough-core/src/language/javascript.rs b/crates/bough-core/src/language/javascript.rs index 4c6b73f7..8226c167 100644 --- a/crates/bough-core/src/language/javascript.rs +++ b/crates/bough-core/src/language/javascript.rs @@ -22,7 +22,12 @@ impl LanguageDriver for JavascriptDriver { "statement_block" => Some((MutantKind::StatementBlock, span_from_node(node))), "if_statement" | "while_statement" | "for_statement" => { let condition = node.child_by_field_name("condition")?; - Some((MutantKind::Condition, span_from_node(&condition))) + let inner = if condition.kind() == "parenthesized_expression" { + condition.child(1).unwrap_or(condition) + } else { + condition + }; + Some((MutantKind::Condition, span_from_node(&inner))) } // bough[impl mutant.twig-iter.find.js.binary.add] // bough[impl mutant.twig-iter.find.js.binary.sub] diff --git a/crates/bough-core/src/mutation.rs b/crates/bough-core/src/mutation.rs index 2bc9d023..5f095430 100644 --- a/crates/bough-core/src/mutation.rs +++ b/crates/bough-core/src/mutation.rs @@ -411,14 +411,14 @@ mod tests { #[test] fn apply_to_complete_src_string_condition() { let src = "if (a > 0) { return 1; }"; - // ^^^^^^^ bytes 3..10 is "(a > 0)" + // ^^^^^ bytes 4..9 is "a > 0" (inside parens) let mutant = Mutant::new( crate::LanguageId::Javascript, Twig::new(PathBuf::from("src/a.js")).unwrap(), MutantKind::Condition, - Span::new(Point::new(0, 3, 3), Point::new(0, 10, 10)), + Span::new(Point::new(0, 4, 4), Point::new(0, 9, 9)), ); let mutation = Mutation { mutant, subst: "true".into() }; - assert_eq!(mutation.apply_to_complete_src_string(src), "if true { return 1; }"); + assert_eq!(mutation.apply_to_complete_src_string(src), "if (true) { return 1; }"); } } -- knotmirror 0.0.1