diff --git a/dprint_plugin/tests/integration/biome/basic.astro.snap b/dprint_plugin/tests/integration/biome/basic.astro.snap
index 6bd287e..090db7b 100644
--- a/dprint_plugin/tests/integration/biome/basic.astro.snap
+++ b/dprint_plugin/tests/integration/biome/basic.astro.snap
@@ -78,6 +78,4 @@ document.getElementById("button").addEventListener("click", handleClick);
/* */
}
-{
- /* https://example.com */
-}
+{/* https://example.com */}
diff --git a/dprint_plugin/tests/integration/dprint_ts/basic.astro.snap b/dprint_plugin/tests/integration/dprint_ts/basic.astro.snap
index 75f90f4..d4950d9 100644
--- a/dprint_plugin/tests/integration/dprint_ts/basic.astro.snap
+++ b/dprint_plugin/tests/integration/dprint_ts/basic.astro.snap
@@ -78,6 +78,4 @@ document.getElementById("button").addEventListener("click", handleClick);
/* */
}
-{
- /* https://example.com */
-}
+{/* https://example.com */}
diff --git a/markup_fmt/src/ast.rs b/markup_fmt/src/ast.rs
index 941c8f0..d264988 100644
--- a/markup_fmt/src/ast.rs
+++ b/markup_fmt/src/ast.rs
@@ -49,6 +49,7 @@ pub struct AstroAttribute<'s> {
pub struct AstroExpr<'s> {
pub children: Vec>,
+ pub has_line_comment: bool,
pub start: usize,
}
diff --git a/markup_fmt/src/parser.rs b/markup_fmt/src/parser.rs
index a1065a0..9d1ccc2 100644
--- a/markup_fmt/src/parser.rs
+++ b/markup_fmt/src/parser.rs
@@ -543,6 +543,7 @@ impl<'s> Parser<'s> {
};
let mut children = Vec::with_capacity(1);
+ let mut has_line_comment = false;
let mut pair_stack = vec![];
let mut pos = self
.chars
@@ -632,8 +633,17 @@ impl<'s> Parser<'s> {
}
'/' if !matches!(pair_stack.last(), Some('\'' | '"' | '`' | '/' | '*')) => {
self.chars.next();
- if let Some((_, c)) = self.chars.next_if(|(_, c)| *c == '/' || *c == '*') {
- pair_stack.push(c);
+ match self.chars.peek() {
+ Some((_, '/')) => {
+ pair_stack.push('/');
+ has_line_comment = true;
+ self.chars.next();
+ }
+ Some((_, '*')) => {
+ pair_stack.push('*');
+ self.chars.next();
+ }
+ _ => {}
}
}
'\n' => {
@@ -663,6 +673,7 @@ impl<'s> Parser<'s> {
Ok(AstroExpr {
children,
+ has_line_comment,
start: start + 1,
})
}
diff --git a/markup_fmt/src/printer.rs b/markup_fmt/src/printer.rs
index ff33db1..c150a34 100644
--- a/markup_fmt/src/printer.rs
+++ b/markup_fmt/src/printer.rs
@@ -280,7 +280,7 @@ impl<'s> DocGen<'s> for AstroExpr<'s> {
.nest_with_ctx(ctx)
.append(Doc::line_or_nil())
.append(Doc::text("}"));
- if script.contains("//") {
+ if self.has_line_comment {
doc
} else {
doc.group()