You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 29b2f8c
Browse filesBrowse the repository at this point in the historyBrowse files
fix(scripts): scan a template's ${...} as code so a nested backtick cannot flip js-comment-mask's parity (#10632)
* fix(scripts): scan a template's ${...} as code, so a nested backtick cannot flip the mask's parity
scanSource walked a template literal's interpolation as plain literal text and
stopped the span at the next backtick. An interpolation is code: it can hold a
nested template (how this tree formats a list of names), a backtick inside a
regex or a string, or a brace inside a string. The nested opener was read as
the outer template's closer, and the phantom span ran to the next backtick
anywhere in the file.
Measured against @typescript-eslint/parser's comment ranges over 4,733 files:
16 files disagreed before (15 in the FABRICATES direction the module's own
header calls the worse one, up to 10,252 comment bytes read as live code in
one file), 0 after.
The interpolation is now scanned by the same loop, with the same string, regex
and comment branches, and its bytes are still reported as the enclosing
template's literal content -- the documented flag is unchanged, so both
consumers of `literal` (check-parse-guard, check-entry-guard) see what they
saw. Seven shapes pinned in --self-test, each asserting both sides (a comment
that must go, live code that must stay); all 22 cases verified byte-for-byte
against the parser.
The header's "cannot fabricate a lead" guarantee was measured false and is
replaced by what can be re-derived.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DdCnBGcHeufjrq7drTD3wt
* test(scripts): pin the interpolation brace shape with a case that a mutation can kill
The `${x ? '}' : '{'}` spelling passed with the brace counting deleted AND with
the pre-fix scanner -- it asserted "no error" and pinned nothing. Replaced with
`${fmt({ a: 1 }, '`')}`, which carries a nested brace and a quoted backtick in
one interpolation: deleting the `{` counting ends the interpolation at the
object literal's `}`, the quoted backtick is then read as the template's
closer, and the docblock below survives the mask.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DdCnBGcHeufjrq7drTD3wt
* test(scripts): pin the interpolation whose object literal precedes a nested template
Deleting the `{` counting inside `${...}` passed all 22 cases and the whole
4,733-file sweep -- the tree does not currently write that shape, so nothing
held it. `${fmt({ a: 1 }, `\``)}` does: without the counting the interpolation
ends at the object literal's `}`, the nested template's delimiters are then
read in body position, and the docblock below survives the mask.
Also records what the mutation runs showed about depth: matched backticks pair
off whatever a scan believes about nesting, so nested-in-nested ALONE is green
under every mutation. Only nesting that meets an escape or a quoted backtick
discriminates.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DdCnBGcHeufjrq7drTD3wt
* docs(scripts): spell out the sweep that measures this scanner, and what it missed
The header pointed at "the sweep" without saying how to run one. It now names
the corpus, the parser and the comparison, so the 16-file census is
re-derivable from the file itself rather than from a PR description.
Also records the result that ranks the two instruments: deleting the `{`
counting inside `${...}` passed every pinned case AND the whole 4,739-file
sweep, because the tree does not happen to write that shape. The case that
holds it now was written from the mutation, not from the corpus.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DdCnBGcHeufjrq7drTD3wt
---------
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments