diff --git a/crates/biome_js_formatter/src/syntax_rewriter.rs b/crates/biome_js_formatter/src/syntax_rewriter.rs index ee4386cf25d0..ff39bd173032 100644 --- a/crates/biome_js_formatter/src/syntax_rewriter.rs +++ b/crates/biome_js_formatter/src/syntax_rewriter.rs @@ -140,6 +140,12 @@ impl JsFormatSyntaxRewriter { let prev_token = l_paren.prev_token(); // Keep parentheses around unknown expressions. Biome can't know the precedence. if inner.kind().is_bogus() + // Don't remove parentheses if the expression in js template element + || inner.grand_parent().is_some_and(|parent| + parent.grand_parent().is_some_and(|node| + node.kind() == JsSyntaxKind::JS_TEMPLATE_ELEMENT + ) + ) // Don't remove parentheses if the expression is a decorator || inner.grand_parent().is_some_and(|node| node.kind() == JsSyntaxKind::JS_DECORATOR && decorator_expression_needs_parens(&inner)) // Don't remove parentheses if they have skipped trivia. We don't know for certain what the intended syntax is. diff --git a/crates/biome_js_formatter/tests/specs/js/module/template/template.js b/crates/biome_js_formatter/tests/specs/js/module/template/template.js index fc8de9fed12f..f2f23c54e6aa 100644 --- a/crates/biome_js_formatter/tests/specs/js/module/template/template.js +++ b/crates/biome_js_formatter/tests/specs/js/module/template/template.js @@ -58,4 +58,15 @@ which already had a linebreak so can be broken up message = `this is a long messsage a simple interpolation without a linebreak \${foo} <- like this\`; message = \`whereas this messsage has a linebreak in the interpolation \${ foo -} <- like this`; \ No newline at end of file +} <- like this`; + +// https://github.com/biomejs/biome/issues/3766 +const issus_3766 = `Lectures: ${doneCount}/${totalCount} | Mins: ${(doneSecs / 60).toFixed( + 2, + )}/${(totalSecs / 60).toFixed( + 2, + )}| Hours: ${(doneSecs / 3600).toFixed( + 2, + )}/${(totalSecs / 3600).toFixed( + 2, + )}`; \ No newline at end of file diff --git a/crates/biome_js_formatter/tests/specs/js/module/template/template.js.snap b/crates/biome_js_formatter/tests/specs/js/module/template/template.js.snap index 86691ab7378d..4e6616228c49 100644 --- a/crates/biome_js_formatter/tests/specs/js/module/template/template.js.snap +++ b/crates/biome_js_formatter/tests/specs/js/module/template/template.js.snap @@ -66,6 +66,17 @@ message = `this is a long messsage a simple interpolation without a linebreak \$ message = \`whereas this messsage has a linebreak in the interpolation \${ foo } <- like this`; + +// https://github.com/biomejs/biome/issues/3766 +const issus_3766 = `Lectures: ${doneCount}/${totalCount} | Mins: ${(doneSecs / 60).toFixed( + 2, + )}/${(totalSecs / 60).toFixed( + 2, + )}| Hours: ${(doneSecs / 3600).toFixed( + 2, + )}/${(totalSecs / 3600).toFixed( + 2, + )}`; ``` @@ -169,6 +180,13 @@ message = `this is a long messsage a simple interpolation without a linebreak \$ message = \`whereas this messsage has a linebreak in the interpolation \${ foo } <- like this`; + +// https://github.com/biomejs/biome/issues/3766 +const issus_3766 = `Lectures: ${doneCount}/${totalCount} | Mins: ${( + doneSecs / 60 +).toFixed(2)}/${(totalSecs / 60).toFixed(2)}| Hours: ${( + doneSecs / 3600 +).toFixed(2)}/${(totalSecs / 3600).toFixed(2)}`; ``` # Lines exceeding max width of 80 characters