Skip to content

Commit 903d7f1

Browse files
authored
fix: handle backslashes in embedded template language reasonably (#714)
1 parent 35eb1df commit 903d7f1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/generation/generate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,8 +3043,8 @@ fn maybe_gen_tagged_tpl_with_external_formatter<'a>(node: &TaggedTpl<'a>, contex
30433043
.unwrap();
30443044

30453045
// Then formats the text with the external formatter.
3046-
let formatted_tpl = match external_formatter(media_type, text, context.config) {
3047-
Ok(formatted_tpl) => formatted_tpl?,
3046+
let formatted_tpl = match external_formatter(media_type, text.replace(r"\\", "\\"), context.config) {
3047+
Ok(formatted_tpl) => formatted_tpl?.replace("\\", r"\\"),
30483048
Err(err) => {
30493049
context.diagnostics.push(context::GenerateDiagnostic {
30503050
message: format!("Error formatting tagged template literal at line {}: {}", node.start_line(), err),

tests/specs/external_formatter/css.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,12 @@ css`${expr}`
147147
css`
148148
${expr};
149149
`;
150+
151+
== should format css that includes \\ ==
152+
css`.bg-\\[\\#86efac\\] { background-color: #86efac; }`
153+
[expect]
154+
css`
155+
.bg-\\[\\#86efac\\] {
156+
background-color: #86efac;
157+
}
158+
`;

0 commit comments

Comments
 (0)