From 56d568074210f2a16c5ca7ef7578169e882612df Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Tue, 6 Oct 2026 17:03:17 +0200 Subject: [PATCH] fix(highlight): keep Astro expressions colored through nested template strings (#6219) An Astro { } expression containing a template string inside ${} closed at the first } in that nested string, leaving the rest of the expression uncolored. Astro and Vue now share one scanner for embedded JavaScript, which already skips template substitutions. Closes #6209 Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> --- .../src/__tests__/highlighter.test.ts | 13 +++ packages/highlight/src/astro/parser.ts | 80 +------------- packages/highlight/src/js-scanner.ts | 100 ++++++++++++++++++ packages/highlight/src/vue/parser.ts | 99 +---------------- 4 files changed, 116 insertions(+), 176 deletions(-) create mode 100644 packages/highlight/src/js-scanner.ts diff --git a/packages/highlight/src/__tests__/highlighter.test.ts b/packages/highlight/src/__tests__/highlighter.test.ts index 386b0c6364..c245d42da1 100644 --- a/packages/highlight/src/__tests__/highlighter.test.ts +++ b/packages/highlight/src/__tests__/highlighter.test.ts @@ -144,6 +144,19 @@ const title = "Hello"; ); }); + it("keeps an Astro expression open through nested template strings", () => { + const code = "
{`a ${`}`} b`}
"; + + const tokens = highlightCode(code, "Nested.astro").flat(); + + expect(tokens).toEqual( + expect.arrayContaining([ + { text: "`}`", style: "string" }, + { text: " b`", style: "string" }, + ]), + ); + }); + it("highlights Vue SFCs across script, template, and style", () => { const code = [ '