Skip to content

Commit a8eb0fe

Browse files
claude[bot]claude
andauthored
fix(devx): js-comment-mask.d.mts declares the interpolation flags and the self-test verdict the module really returns (#15534, #15398) (#15593)
Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk Co-authored-by: Claude <noreply@anthropic.com>
1 parent f1d7872 commit a8eb0fe

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

scripts/js-comment-mask.d.mts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// scanner silently becomes `any`, and reading `.comment` off a misspelled
1212
// property would type-check clean.
1313
//
14-
// The two flag arrays are the load-bearing part of the surface, so they are
14+
// The three flag arrays are the load-bearing part of the surface, so they are
1515
// typed precisely: a caller that confuses them inverts the very question this
1616
// module exists to answer once (see the module's header on the two failure
1717
// families).
@@ -23,21 +23,32 @@
2323
/**
2424
* Per-character flags from one left-to-right pass over a JS source.
2525
*
26-
* Both arrays are the same length as the source, so an offset into either
27-
* indexes the same character in the original text.
26+
* All three arrays are the same length as the source, so an offset into any of
27+
* them indexes the same character in the original text.
2828
*
2929
* `comment` flags comment CONTENT (line, block and shebang). `literal` flags
3030
* the CONTENT of a string, template or regex literal — **not** its delimiters,
3131
* so a caller still sees the opening and closing quote as code and can pair
3232
* them. Template interiors are flagged through `${...}` as well.
33+
*
34+
* `interpolation` flags the bytes a template interpolation contributes, which
35+
* the language RUNS as code. Those same bytes are flagged `literal` too — that
36+
* answer does not move — so a caller wanting the view the language would
37+
* execute masks `literal && !interpolation`, which is exactly how
38+
* `scripts/pm/dispatch-gates.mjs` counts an identifier inside `${...}` as a
39+
* reference. The `${` and its closing `}` stay OUT of it (a bracket counter
40+
* over the subtracted view stays balanced), and so does a nested template's
41+
* body inside the interpolation (those bytes really are content).
3342
*/
3443
export interface SourceFlags {
3544
comment: Uint8Array;
3645
literal: Uint8Array;
46+
interpolation: Uint8Array;
3747
}
3848

3949
/**
40-
* Flag every character of `source` as comment content and/or literal content.
50+
* Flag every character of `source` as comment content, literal content and/or
51+
* interpolation code.
4152
*
4253
* @param source JavaScript (or TypeScript-shaped) source text.
4354
*/
@@ -110,7 +121,12 @@ export function makeRegexRecogniser(options: {
110121
/**
111122
* Drive the scanner over its own fixture corpus, printing a line per case.
112123
*
113-
* Returns nothing: a failing case calls `process.exit(1)` rather than reporting
114-
* a value, so there is no verdict for a caller to forget to read.
124+
* Returns the module's verdict sentinel, reached only once the success line has
125+
* been printed — the handshake its own CLI dispatch performs: that dispatch
126+
* compares the returned value by identity and exits 1 on anything else, so a
127+
* `return` leaving this function above the verdict cannot be reported as a
128+
* self-test that passed. A failing case still calls `process.exit(1)`. The
129+
* sentinel constant is not exported, so `string` is the widest type a caller
130+
* can name for it.
115131
*/
116-
export function selfTest(): void;
132+
export function selfTest(): string;

0 commit comments

Comments
 (0)