@@ -445,7 +445,7 @@ pub(crate) fn parse_astro_embedded_script(
445445 settings : & Settings ,
446446) -> Option < ( EmbeddedSnippet < JsLanguage > , DocumentFileSource ) > {
447447 let content = element. content_token ( ) ?;
448- let file_source = JsFileSource :: ts ( ) . with_embedding_kind ( EmbeddingKind :: Astro ) ;
448+ let file_source = JsFileSource :: ts ( ) . with_embedding_kind ( EmbeddingKind :: AstroFrontmatter ) ;
449449 let document_file_source = DocumentFileSource :: Js ( file_source) ;
450450 let options = settings. parse_options :: < JsLanguage > ( path, & document_file_source) ;
451451 let parse = parse_js_with_offset_and_cache (
@@ -672,8 +672,8 @@ fn format_embedded(
672672 let mut iter = embedded_nodes. iter ( ) ;
673673 let node = iter. find ( |node| node. range == range) ?;
674674
675- let wrap_document = |document : Document | {
676- if indent_script_and_style {
675+ let wrap_document = |document : Document , is_astro_frontmatter : bool | {
676+ if indent_script_and_style && !is_astro_frontmatter {
677677 let elements = vec ! [
678678 FormatElement :: Line ( LineMode :: Hard ) ,
679679 FormatElement :: Tag ( Tag :: StartIndent ) ,
@@ -693,27 +693,31 @@ fn format_embedded(
693693 } ;
694694
695695 match node. source {
696- DocumentFileSource :: Js ( _ ) => {
696+ DocumentFileSource :: Js ( file_source ) => {
697697 let js_options = settings. format_options :: < JsLanguage > ( biome_path, & node. source ) ;
698698 let node = node. node . clone ( ) . embedded_syntax :: < JsLanguage > ( ) . clone ( ) ;
699699 let formatted =
700700 biome_js_formatter:: format_node_with_offset ( js_options, & node) . ok ( ) ?;
701- Some ( wrap_document ( formatted. into_document ( ) ) )
701+
702+ Some ( wrap_document (
703+ formatted. into_document ( ) ,
704+ file_source. as_embedding_kind ( ) == & EmbeddingKind :: AstroFrontmatter ,
705+ ) )
702706 }
703707 DocumentFileSource :: Json ( _) => {
704708 let json_options =
705709 settings. format_options :: < JsonLanguage > ( biome_path, & node. source ) ;
706710 let node = node. node . clone ( ) . embedded_syntax :: < JsonLanguage > ( ) . clone ( ) ;
707711 let formatted =
708712 biome_json_formatter:: format_node_with_offset ( json_options, & node) . ok ( ) ?;
709- Some ( wrap_document ( formatted. into_document ( ) ) )
713+ Some ( wrap_document ( formatted. into_document ( ) , false ) )
710714 }
711715 DocumentFileSource :: Css ( _) => {
712716 let css_options = settings. format_options :: < CssLanguage > ( biome_path, & node. source ) ;
713717 let node = node. node . clone ( ) . embedded_syntax :: < CssLanguage > ( ) ;
714718 let formatted =
715719 biome_css_formatter:: format_node_with_offset ( css_options, & node) . ok ( ) ?;
716- Some ( wrap_document ( formatted. into_document ( ) ) )
720+ Some ( wrap_document ( formatted. into_document ( ) , false ) )
717721 }
718722 _ => None ,
719723 }
0 commit comments