Files
scriptc/tests/corpus/regex-optional-captures.ts
Chris Tate a07998f667 Expand static three.js workflows and host integration (#621)
* Expand static three.js workflows and host integration

* Preserve JavaScript class state in static three.js workflows

* Preserve inferred JavaScript behavior across static workflows

* Preserve inferred callables and native compatibility boundaries

* Retain annotated JavaScript factory exports and bootstrap-safe call spreads

* Preserve Buffer and child callback identities in static packages

* Clarify JavaScript symbol spread support
2026-10-02 19:56:34 -05:00

15 lines
727 B
TypeScript

const expression = /^(a)?(b*)$/;
for (const input of ["", "b", "ab"]) {
const match = expression.exec(input);
if (match === null) throw new Error("missing match");
console.log(input, JSON.stringify(match), match[1] === undefined, match[2] === "", 1 in match);
const matched = input.match(expression);
console.log(JSON.stringify(matched));
}
for (const match of "b ab".matchAll(/(a)?(b)/g)) {
console.log(JSON.stringify(match), match[1] === undefined, 1 in match);
}
const named = /(?<prefix>a)?(?<empty>b*)/.exec("")!.groups!;
console.log(named.prefix === undefined, named.empty === "", JSON.stringify(named), Object.keys(named).join(","));
console.log(/(?<value>a*)x|(?<value>b)/.exec("x")!.groups!.value === "");