diff --git a/crates/biome_formatter/src/format_element/document.rs b/crates/biome_formatter/src/format_element/document.rs index 3363858f269f..53372cc8e9ae 100644 --- a/crates/biome_formatter/src/format_element/document.rs +++ b/crates/biome_formatter/src/format_element/document.rs @@ -250,7 +250,23 @@ impl Format for &[FormatElement] { FormatElement::Space | FormatElement::HardSpace => { write!(f, [text(" ")])?; } - element if element.is_text() => f.write_element(element.clone())?, + element if element.is_text() => { + // escape quotes + let new_element = match element { + // except for static text because source_position is unknown + FormatElement::StaticText { .. } => element.clone(), + FormatElement::DynamicText { text, source_position } => { + let text = text.to_string().replace("\"", "\\\""); + FormatElement::DynamicText { text: text.into(), source_position: *source_position } + }, + FormatElement::LocatedTokenText { slice, source_position } => { + let text = slice.to_string().replace("\"", "\\\""); + FormatElement::DynamicText { text: text.into(), source_position: *source_position } + }, + _ => unreachable!(), + }; + f.write_element(new_element)?; + }, _ => unreachable!(), }