Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 336a9eb

Browse files
baozhoutaoclaude
andauthored
chore(scripts): retire the deJsxClosingTags workaround in check-vi-mock-inherit (#8133)
The shared masker `scripts/js-comment-mask.mjs` has known since objectui#6891 (PR #7880) that a `/` whose immediately preceding byte is `<` opens no regex, so this gate's local length-preserving rewrite of JSX closing tags no longer changes any reading. Re-measured on this base rather than trusting the card's older figure: walking all 1763 `vi.mock` call sites in 4380 tracked sources with every specifier judged, the RAW mask (rewrite NOT applied) yields 0 sites whose argument list does not balance; the same walk against a copy of the masker with objectui#6891's rule reverted yields 6 in 6 files, one of them the covered `@object-ui/react` site the header names, so the 0 is a live reading and not a collapsed walk. `pnpm check:vi-mock-inherit` is byte-identical before and after this commit. Removed: `JSX_CLOSING_TAG`, `deJsxClosingTags`, its call in `findCallSites` (a pure substitution -- the rewritten source was only ever the input to `scanSource`/`blank`), the test's import of it, and its two unit cases. The two behavioural cases stay and pass with no rewrite in the gate at all; they are the evidence the removal changed nothing. The header section keeps its measured history in the past tense and now records objectui#6891 as closed -- and states explicitly that only the `<` `/` half is closed, the other half being objectui#7882, still open. Claude-Session: https://claude.ai/code/session_01FhBNJcLRZLe8M87VcUgpKr Co-authored-by: Claude <noreply@anthropic.com>
1 parent 23933ae commit 336a9eb

2 files changed

Lines changed: 53 additions & 67 deletions

File tree

‎scripts/__tests__/check-vi-mock-inherit.test.ts‎

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { fileURLToPath } from 'node:url';
1111
import {
1212
COVERED_SPECIFIERS,
1313
FLOORS,
14-
deJsxClosingTags,
1514
findCallSites,
1615
scan,
1716
summarise,
@@ -335,22 +334,33 @@ describe('only text the language would execute', () => {
335334
});
336335

337336
// ---------------------------------------------------------------------------
338-
// The JSX mask — a real mis-mask in the shared scanner, measured
337+
// The JSX mask — a real mis-mask in the shared scanner, since fixed
339338
// ---------------------------------------------------------------------------
340339

341-
describe('deJsxClosingTags — the shared masker USED to read `</div>` as a regex literal', () => {
340+
describe('a JSX closing tag — the shared masker USED to read `</div>` as a regex literal', () => {
342341
/**
343342
* `js-comment-mask` opened a regex when a `/` followed something that is not
344343
* a value. In `</div>` that something is `<`, so a PHANTOM regex opened and
345344
* ran to the end of the line, swallowing whatever was there — including the
346345
* `)` that closes a `vi.mock` call. Measured on this tree at the time: SEVEN
347346
* call sites could not be delimited at all, one of them a covered site.
348347
*
349-
* Fixed in the shared module by objectui#6891, whose own pin
350-
* (`scripts/__tests__/js-comment-mask-jsx-6891.test.ts`) now holds the
351-
* scanner. `deJsxClosingTags` stays: it is still correct, still length-
352-
* preserving, and removing it belongs to whoever owns THIS gate's source.
353-
* The first case below is what makes that a decision rather than a guess.
348+
* That is history. The shared masker handles `</tag>` itself since
349+
* objectui#6891, whose own pin
350+
* (`scripts/__tests__/js-comment-mask-jsx-6891.test.ts`) holds the scanner,
351+
* and THIS gate rewrites nothing before masking any more — objectui#7883
352+
* retired the local `deJsxClosingTags` workaround and its two unit cases
353+
* with it.
354+
*
355+
* The three cases below are what say the retirement changed nothing: the
356+
* first reads the mask directly on the RAW source, and the two behavioural
357+
* ones drive the gate end to end on a factory that returns JSX. They pass
358+
* with no rewrite in the gate at all.
359+
*
360+
* ⛔ Not a claim that the masker is correct on JSX: objectui#6891 closed
361+
* only the `<` `/` half, and a `/` after `}` or `>` still opens a phantom
362+
* (objectui#7882, still open). The retired rewrite never covered that half
363+
* either, so nothing was lost with it.
354364
*/
355365

356366
const jsxFactory = `({ open, children }: any) => (open ? <div>{children}</div> : null)`;
@@ -363,10 +373,11 @@ describe('deJsxClosingTags — the shared masker USED to read `</div>` as a rege
363373
// whose immediately preceding byte is `<` opens nothing, and this case
364374
// has been turned over to pin the fix instead.
365375
//
366-
// `deJsxClosingTags` is deliberately NOT removed in that change — it is a
367-
// second gate's source, outside that card's file surface. It is now a
368-
// no-op-in-effect on this shape, and the assertions below are what say so:
369-
// the raw source, WITHOUT the rewrite, already masks correctly.
376+
// `deJsxClosingTags` was deliberately NOT removed in that change — it was
377+
// a second gate's source, outside that card's file surface. objectui#7883
378+
// then retired it, and these assertions are what made that a decision
379+
// rather than a guess: the raw source, with no rewrite anywhere, already
380+
// masks correctly.
370381
const src = `const C = ${jsxFactory};\n`;
371382
const { literal } = scanSource(src);
372383
const inside = src.indexOf('</div>') + 2;
@@ -377,26 +388,11 @@ describe('deJsxClosingTags — the shared masker USED to read `</div>` as a rege
377388
expect(literal[src.lastIndexOf(')')]).toBe(0);
378389
});
379390

380-
it('neutralises the tag while PRESERVING LENGTH, so every offset still holds', () => {
381-
const src = 'a</div>b</>c</Foo.Bar>z';
382-
const out = deJsxClosingTags(src);
383-
expect(out).toHaveLength(src.length);
384-
expect(out).toBe('a<____>b<_>c<________>z');
385-
// Every offset past the rewrite still indexes the same byte, which is what
386-
// lets the mask's flags be read against the ORIGINAL source.
387-
expect(out.indexOf('z')).toBe(src.indexOf('z'));
388-
});
389-
390-
it('leaves a `/` that is not a closing tag alone — a regex, a path, a division', () => {
391-
for (const src of ['const re = /<x>/;', 'const p = "a/b";', 'const q = a / b;', 'x.replace(/</g, "&lt;");']) {
392-
expect(deJsxClosingTags(src)).toBe(src);
393-
}
394-
});
395-
396391
it('THE CONSEQUENCE: a covered factory returning JSX is READ, not skipped', () => {
397-
// Without the workaround this call site is `unreadable`. `unreadable` fails
398-
// the gate, so the mis-mask would not have been silent — but it would have
399-
// reddened five innocent files instead of judging them.
392+
// Under the mis-mask this call site was `unreadable`. `unreadable` fails
393+
// the gate, so the defect would not have been silent — but it would have
394+
// reddened five innocent files instead of judging them. This case is now
395+
// the load-bearing half: it goes red if the shared masker ever regresses.
400396
const site = verdictOf(`async (importOriginal) => ({ ...(await importOriginal()), C: ${jsxFactory} })`);
401397
expect(site.verdict).toBe('inherits');
402398
});

‎scripts/check-vi-mock-inherit.mjs‎

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -302,32 +302,35 @@
302302
* the shared `js-comment-mask.mjs`, exactly as the sibling gate does it, and
303303
* for the same reasons (this file's own header quotes the defect in prose).
304304
*
305-
* ## `js-comment-mask` reads a JSX closing tag as a regex literal
305+
* ## `js-comment-mask` USED to read a JSX closing tag as a regex literal
306306
*
307-
* The shared masker decides a `/` opens a regex when the preceding character is
308-
* not a value. In `</div>` the preceding character is `<`, so it opens a
309-
* PHANTOM regex that runs to the end of the line and swallows whatever is
307+
* Kept as measured history: it is why the shared module was fixed, and the two
308+
* behavioural cases in this gate's test still pin the outcome.
309+
*
310+
* The shared masker decided a `/` opens a regex when the preceding character is
311+
* not a value. In `</div>` the preceding character is `<`, so it opened a
312+
* PHANTOM regex that ran to the end of the line and swallowed whatever was
310313
* there -- including the `)` that closes a `vi.mock` call.
311314
*
312-
* That is not hypothetical here: measured on this tree, SEVEN `vi.mock` call
313-
* sites in five files could not have their argument list delimited at all
314-
* because of it, one of them a covered `@object-ui/react` site
315+
* That was not hypothetical here: measured on this tree at the time, SEVEN
316+
* `vi.mock` call sites in five files could not have their argument list
317+
* delimited at all because of it, one of them a covered `@object-ui/react` site
315318
* (`plugin-dashboard/src/__tests__/ObjectDataTable.cells.test.tsx`). The sibling
316319
* gate never noticed because it only reads the specifier; this gate reads the
317-
* factory BODY, so it cannot.
318-
*
319-
* `deJsxClosingTags` neutralises it, and the shape of the fix is what keeps it
320-
* safe: a JSX closing tag is rewritten to the SAME NUMBER OF BYTES
321-
* (`</div>` -> `<____>`) before masking, so every offset the mask returns still
322-
* indexes the original source, and the only bytes that change are slashes that
323-
* cannot be part of a spread, an identifier, or a specifier. A `</` inside a
324-
* string or a regex is rewritten too and does not matter: it is literal content
325-
* either way, and its quotes are untouched, so nothing structural moves.
326-
* Measured: the seven unreadable sites become zero, and no site changes verdict.
327-
*
328-
* This is a LOCAL workaround in this gate, not a change to the shared masker --
329-
* that module is used by many gates and its JSX behaviour is filed separately
330-
* as objectui#6891.
320+
* factory BODY, so it could not.
321+
*
322+
* This gate carried a LOCAL workaround for it -- `deJsxClosingTags`, a
323+
* length-preserving rewrite of every closing tag applied before masking. The
324+
* shared masker itself was then fixed by objectui#6891 (CLOSED, PR #7880),
325+
* which taught `scanSource` that a `/` whose immediately preceding byte is `<`
326+
* opens nothing. Re-measured on the fixed masker, the raw source with the
327+
* rewrite NOT applied has ZERO undelimitable sites and the gate's verdict is
328+
* byte-identical either way, so the workaround was retired by objectui#7883.
329+
* ⛔ That is not "the masker is correct on JSX": objectui#6891 closed only the
330+
* `<` `/` half. A `/` after `}` or `>` -- a self-closing tag, a `/` in JSX text
331+
* -- still opens a phantom; that half is objectui#7882 and is still open. The
332+
* retired rewrite never covered it either (its pattern matched closing tags
333+
* only), which is why removing it lost no coverage.
331334
*/
332335

333336
import { execFileSync } from 'node:child_process';
@@ -382,18 +385,6 @@ export const FLOORS = Object.freeze({
382385
covered: 50,
383386
});
384387

385-
/** A JSX closing tag: `</div>`, `</Foo.Bar>`, `</>`. */
386-
const JSX_CLOSING_TAG = /<\/([A-Za-z_$][\w$.:-]*)?\s*>/g;
387-
388-
/**
389-
* `source` with the slash of every JSX closing tag replaced, PRESERVING LENGTH,
390-
* so offsets from the mask still index the original. See the header section on
391-
* `js-comment-mask` for the measurement that made this necessary.
392-
*/
393-
export function deJsxClosingTags(source) {
394-
return source.replace(JSX_CLOSING_TAG, (m) => `<${'_'.repeat(m.length - 2)}>`);
395-
}
396-
397388
/** 1-based line number of `offset` in `source`. */
398389
function lineOf(source, offset) {
399390
let line = 1;
@@ -682,9 +673,8 @@ export function classifyFactory(masked, literal, start, end, specifier) {
682673
* for the instance that made this distinction necessary).
683674
*/
684675
export function findCallSites(source, { covered = COVERED_SPECIFIERS } = {}) {
685-
const dejsxed = deJsxClosingTags(source);
686-
const { comment, literal } = scanSource(dejsxed);
687-
const masked = blank(dejsxed, comment);
676+
const { comment, literal } = scanSource(source);
677+
const masked = blank(source, comment);
688678
const coveredSet = new Set(covered);
689679

690680
const sites = [];

0 commit comments

Comments
 (0)