Skip to content

Commit

Permalink
address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-yu committed May 8, 2024
1 parent 73f99ad commit 43493fa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/biome_js_formatter/src/js/auxiliary/template_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::js::lists::template_element_list::TemplateElementIndention;
use biome_js_syntax::{
AnyJsExpression, JsSyntaxNode, JsSyntaxToken, JsTemplateElement, TsTemplateElement,
};
use biome_rowan::{declare_node_union, AstNode, SyntaxResult};
use biome_rowan::{declare_node_union, AstNode, NodeOrToken, SyntaxResult};

enum TemplateElementLayout {
/// Tries to format the expression on a single line regardless of the print width.
Expand Down Expand Up @@ -218,7 +218,17 @@ impl AnyTemplateElement {
}

fn has_new_line_in_range(&self) -> bool {
self.syntax().text().contains_char('\n')
fn has_new_line_in_node(node: &JsSyntaxNode) -> bool {
node.children_with_tokens().any(|child| match child {
NodeOrToken::Token(token) => token
// no need to check for trailing trivia as it's not possible to have a new line
.leading_trivia()
.pieces()
.any(|trivia| trivia.is_newline()),
NodeOrToken::Node(node) => has_new_line_in_node(&node),
})
}
has_new_line_in_node(self.syntax())
}
}

Expand Down

0 comments on commit 43493fa

Please sign in to comment.