mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 08:35:07 +08:00
- lowerRegexLiteral drops the (?<name> fence: patterns and \k<name> backreferences run natively in libregexp, and .groups on exec/match/matchAll results desugars into a compile-time record projection over the honest slice — the checker's own Record<string,string> hybrid with overflow entries in group declaration order — whenever the regex is statically known (literals, const bindings, new RegExp("..."), matchAll rows via for-of bindings, stored drains, spread rows, element access)
- Node's exact shapes: a group-less regex answers .groups === undefined, nullable receivers throw Node's TypeError on the unit arms, ES2025 duplicate names project the participating alternative, and destructuring rides — flat, aliased, and the nested { groups: { year } } pattern — via the groups wrap plus a general overflow read for undeclared keys of index-signature shapes
- scr_put_substitution resolves $<name> against lre_get_groupnames with Node's edge answers: nonexistent and nonparticipating names substitute empty, $< stays literal when the pattern has no named groups, an unterminated $<name stays literal
- s.match(re) also claims a nullable string receiver (the Dict<string> member spelling) through the checked narrow; an untraceable .groups read keeps the SC2020 fence with a hint naming the traceable shapes
- Differential corpus 2604-2607 (both backends, SAN), runtime C substitution/backreference cases, refreshed diagnostics snapshots and surface manifest; corpus 1614's deliberate deferred fence moves to a Proxy wrap now that hybrid record reads compile
18 lines
684 B
TypeScript
18 lines
684 B
TypeScript
// The regex slice fences. test() on a g/y-flagged literal is the
|
|
// statefulness fence (lastIndex is not modeled); the d/v flags are
|
|
// outside the slice; .groups needs a statically-known regex (named
|
|
// capture groups themselves compile — corpus 2604); method-as-value has
|
|
// no value form; regexes stay out of union arms (ARRAYS of regexes
|
|
// compile — corpus 2448).
|
|
const g = /ab/g.test("abab");
|
|
const y = /ab/y.test("abab");
|
|
const indices = /cat/d;
|
|
const sets = /[\p{L}]/v;
|
|
const asValue = /x/.test;
|
|
const maybe: RegExp | undefined = /a/;
|
|
function readGroups(re: RegExp): void {
|
|
const m = re.exec("2024-07");
|
|
if (m) console.log(m.groups);
|
|
}
|
|
readGroups(/(?<year>\d{4})/);
|