withastro / astro · Issue No. 17544
Astro v7.1.3
Node v26.5.0
System macOS (arm64)
Package Manager pnpm
Output static
Adapter none
Integrations none
No response
A template literal containing another template literal nested inside a ${} expression fails to compile in the frontmatter, throwing [CompilerError] Unexpected token. This is valid JS/TS and worked in Astro 6 and earlier.
Reproduction
---
let hideTitle = false;
let title = "Hello";
let srcdoc = `<div>${hideTitle ? '' : `<span>${title}</span>`}</div>`;
---
<div>{srcdoc}</div>
Running astro build fails with:
[CompilerError] Unexpected token
pointing at the frontmatter block.
Expected behavior
Nested template literals should parse normally, as they do in standard JS/TS and in Astro 6.
Workaround
Pulling the inner template literal out into its own variable avoids the issue:
---
let inner = hideTitle ? '' : `<span>${title}</span>`;
let srcdoc = `<div>${inner}</div>`;
---
Additional context
This appears to be a limitation in the new compiler-rs frontmatter compiler introduced as part of the Rolldown/Vite 8 migration, it doesn't seem to track backtick nesting depth correctly inside ${} expressions.
Nested template literals should parse normally, as they do in standard JS/TS and in Astro 6.
NA
Relay reads this issue against the repository's contribution signals: the files it is likely to touch, how the maintainers triage work this size, and what the first contribution would exercise.
The full analysis for this issue is still being assembled. Until then, the description above and the thread on GitHub are the most reliable context.