Commit 19fa30c
refactor(devx): share the regex-literal walk, keep the position rule a parameter (#15532)
* refactor(devx): share the regex-literal WALK, keep the position rule a parameter
`scripts/js-comment-mask.mjs` and `scripts/check-dispatcher-error-vocabulary.mjs`
each carried a regex-literal recogniser: a byte-identical 14-word
`REGEX_AFTER_KEYWORD` set, an `IDENT_CHAR` class, and a body walk. The keyword
set is not decorative — js-comment-mask's own header records that dropping
`return` from it passes all 23 of its self-test cases and is caught only by the
corpus sweep, so the copy that drifts drifts silently in exactly the direction
its owner warns about.
Split by NUMBER OF RIGHT ANSWERS rather than by module:
the WALK has one (ECMA-262's), so it lives once — `walkRegexBody`, exported
from js-comment-mask.mjs alongside `IDENT_CHAR` and `REGEX_AFTER_KEYWORD`;
the POSITION RULE has two, because the consumers fail in deliberately
opposite directions — a masker over-masks safely, a scanner must never skip
a span it invented — so it is a parameter (`makeRegexRecogniser`), with no
default and a throw when one is omitted.
`walkRegexBody` returns `{ end, closed }` rather than a verdict: an unclosed
body is where the two directions part, so the shared half reports the outcome
and each caller decides. `scanSource` over-masks to `end` and reads on (198
positions on this tree, every one a JSX closing tag); the gate answers -1.
Zero behaviour change, measured both sides:
scanSource(BASE) vs scanSource(HEAD) over the same 5929-file corpus
population — comment, literal, interpolation, maskComments and stripComments
all byte-identical: 0 files differ, 0 flag bytes differ.
check-dispatcher-error-vocabulary normal, --report and --self-test output
byte-identical, self-test still 10 shapes + 322 assertions.
#14742's two cross-fixture self-test cases are KEPT and still mean what they
said: the two POSITION RULES are still two, so pinning them against each other
on the agreeing fixtures and on the `}` divergence still guards a real thing.
js-comment-mask --self-test gains a 9-assertion shared-recogniser section
driven in BOTH position modes, with a literal roster and floor of its own:
23 mask/strip corpus + 12 interpolation view + 9 shared recogniser = 44.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk
* fix(devx): makeRegexRecogniser takes a REQUIRED options parameter
`check-declaration-mirrors` went red in CI:
scripts/js-comment-mask.d.mts:106 declares `makeRegexRecogniser` with 1
required parameter(s), but scripts/js-comment-mask.mjs implements 0.
`Function.length` counts the parameters BEFORE the first defaulted one, so
`makeRegexRecogniser({ mayBeginAt } = {})` reports zero required arguments. The
declaration is the honest side — there is no default position rule, so the
options really are required — and the module is what was wrong.
Dropped the `= {}` and read `mayBeginAt` longhand behind an `options == null`
guard, which keeps the existing TypeError message rather than letting a bare
destructuring TypeError replace it with one that explains nothing. No behaviour
change beyond the arity: both `makeRegexRecogniser()` and a non-function rule
still throw, with the same message.
The self-test row that already covered "omitting the rule throws" now pins all
three facts at once — both throws, the message, and
`makeRegexRecogniser.length === 1` — so the module's own `--self-test` reds on
this regression instead of only a gate one layer away. Ablated: restoring the
`= {}` gives `Function.length` 0, `js-comment-mask --self-test` EXIT=1 on that
row, and `check-declaration-mirrors` EXIT=1 with the exact CI message above.
The row name and count are unchanged, so the verdict still reads 44 cases
(23 mask/strip corpus, 12 interpolation view, 9 shared recogniser).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0c5e973 commit 19fa30c
3 files changed
Lines changed: 373 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
219 | 233 | | |
220 | 234 | | |
221 | 235 | | |
| |||
1481 | 1495 | | |
1482 | 1496 | | |
1483 | 1497 | | |
1484 | | - | |
1485 | | - | |
1486 | | - | |
1487 | | - | |
1488 | | - | |
1489 | | - | |
1490 | | - | |
1491 | | - | |
1492 | | - | |
1493 | | - | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
1494 | 1506 | | |
1495 | 1507 | | |
1496 | 1508 | | |
| |||
1544 | 1556 | | |
1545 | 1557 | | |
1546 | 1558 | | |
1547 | | - | |
1548 | | - | |
1549 | | - | |
1550 | | - | |
1551 | | - | |
1552 | | - | |
1553 | | - | |
1554 | | - | |
1555 | | - | |
1556 | | - | |
1557 | | - | |
1558 | | - | |
1559 | | - | |
1560 | | - | |
1561 | | - | |
1562 | | - | |
1563 | | - | |
1564 | | - | |
1565 | | - | |
1566 | | - | |
1567 | | - | |
1568 | | - | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
| 1559 | + | |
1573 | 1560 | | |
1574 | 1561 | | |
1575 | 1562 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
68 | 110 | | |
69 | 111 | | |
70 | 112 | | |
| |||
0 commit comments