track html comments so prose backticks stop desyncing the scanner

This commit is contained in:
doxa-maps-88655c70 2026-09-21 06:19:37 +00:00
parent 08cbccb7ba
commit 9e3443333f

View file

@ -74,6 +74,12 @@ for (const file of FILES) {
let inComment = false // /* */ inside a template literal
let inQuote = null // ' or " — a backtick in here is legitimate (e.g. an error message)
let inLineComment = false
// ★ HTML COMMENTS (2026-09-21). 13 of our .vue files OPEN with a <!-- ... --> block whose prose
// uses markdown backticks (e.g. "the `title` prop"). The scanner had no notion of them, so every
// one of those backticks TOGGLED inTemplate and its state was scrambled before it ever reached
// real code. That latent desync is why a first attempt to widen this gate to live CSS produced
// 98 FALSE POSITIVES on a clean tree. Skipping HTML comments is the upstream fix.
let inHtmlComment = false
let line = 1
for (let i = 0; i < src.length; i++) {
@ -83,6 +89,16 @@ for (const file of FILES) {
if (c === '\n') { line++; inLineComment = false; continue }
if (src[i - 1] === '\\') continue // escaped char — skip
// HTML comments FIRST — they wrap prose, and prose backticks must never touch our state.
// Only honoured OUTSIDE a template literal: a "<!--" inside CSS is not a comment opener there.
if (!inTemplate && !inQuote && !inHtmlComment && c === '<' && src.startsWith('<!--', i)) {
inHtmlComment = true; i += 3; continue
}
if (inHtmlComment) {
if (c === '-' && src.startsWith('-->', i)) { inHtmlComment = false; i += 2 }
continue
}
// A // line comment outside a template literal: skip to end of line.
if (!inTemplate && !inQuote && !inLineComment && c === '/' && next === '/') { inLineComment = true; i++; continue }
if (inLineComment) continue