mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
* 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
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
// s.matchAll(/re/g): every match as its honest string[] slice (match's
|
|
// rule — [whole, ...captures], nonparticipating captures read undefined), in
|
|
// the two lowered consumer shapes: the immediate [...spread] + map (the
|
|
// portless plist scraper) and the direct for-of walk. Empty matches
|
|
// advance one position (the spec's AdvanceStringIndex). A non-global
|
|
// regex throws Node's exact TypeError, catchably.
|
|
const block = "<key>PATH</key> <string>/usr/bin</string>\n<key>HOME</key> <string>/root</string>";
|
|
|
|
const strings = [...block.matchAll(/<string>([\s\S]*?)<\/string>/g)].map((match) => match[1]);
|
|
console.log(strings.length, strings.join("|"));
|
|
|
|
for (const match of block.matchAll(/<key>([\s\S]*?)<\/key>\s*<string>([\s\S]*?)<\/string>/g)) {
|
|
console.log(match.length, match[0].length, match[1], match[2]);
|
|
}
|
|
|
|
// No match drains to the empty array; empty matches advance.
|
|
console.log([...("abc".matchAll(/x/g))].length);
|
|
const empties = [...("ab".matchAll(/z?/g))];
|
|
console.log(empties.length);
|
|
|
|
// Nonparticipating captures retain undefined; formatting may use a fallback.
|
|
for (const m of "a1 b".matchAll(/([ab])(\d)?/g)) {
|
|
console.log(`[${m[0]}|${m[1]}|${(m[2] as string | undefined) ?? ""}]`);
|
|
}
|
|
|
|
// The non-global form throws Node's exact TypeError.
|
|
const re = /never-global/;
|
|
try {
|
|
"x".matchAll(re);
|
|
console.log("no-throw");
|
|
} catch (e) {
|
|
console.log("caught", e instanceof TypeError, (e as Error).message);
|
|
}
|