fix: don't double backslash escapes in non-CSS embedded templates#801
Open
bartlomieju wants to merge 1 commit into
Open
fix: don't double backslash escapes in non-CSS embedded templates#801bartlomieju wants to merge 1 commit into
bartlomieju wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When formatting embedded code in tagged templates, lone escape sequences get
their backslash doubled, which changes the meaning of the user's code:
Root cause
maybe_gen_tagged_tpl_with_external_formatterunescapes\\->\beforecalling the external formatter and then re-escapes every
\->\\afterwards. The blanket post-doubling also doubles lone escapes (
\n,\`)that were never part of a
\\pair.The
\\->\collapse is genuinely needed for CSS: the CSS parser cannotparse the double-backslash form of escapes (e.g. Tailwind
.bg-\\[\\#86efac\\]errors; it needs.bg-\[\#86efac\]). But it must not beapplied to other embedded languages.
Fix
Gate the
\\<->\round-trip toembedded_lang == "css". Other languages(html / xml / svg / sql) pass the raw text through verbatim, preserving their
escapes. The existing CSS
\\(Tailwind) behavior is unchanged.Test
Added a regression spec to
tests/specs/external_formatter/html.txtassertinghtml`\n`stays\n. Verified it fails before the fix and passes after; theexisting CSS
\\spec still passes.This PR was authored and opened with AI assistance (Claude Code). The fix was
manually verified end-to-end against Deno's formatter (which embeds this plugin):
it resolves denoland/deno#30103 and denoland/deno#30948, with Deno's full
fmtspec suite passing.