mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-30 07:14:39 +08:00
- T[K] resolves against record bindings, Object.hasOwn/assign lower over records and the DOM, fixed shapes take runtime-keyed writes with the miss trap, and string|RegExp unions narrow by instanceof - the width family gains the checked NARROW lift and the tuple-arm literal route (the option-table shapes) - island literals complete: get accessors, plain spreads, tagged templates with .raw, jsval ??, and call-time fence deferral for unlowerable members (lambda poisons defer too) - JS variadic rests under --dynamic bind the engine arguments array and re-invoke through apply; dyn values marshal into the island as the deep copy - corpus 2470-2476 pin every landing against the Node oracle on both backends
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
// The skip-utility shape: a `string | RegExp` parameter dispatching on
|
|
// `instanceof RegExp` (the union's regex-arm tag test), the RegExp arm
|
|
// driving .test and the string arm .includes; plus a `RegExp | undefined`
|
|
// slot narrowing by tag.
|
|
function skip(characters: string | RegExp): (text: string, startIndex: number) => number {
|
|
return (text, startIndex) => {
|
|
let cursor = startIndex;
|
|
while (cursor >= 0 && cursor < text.length) {
|
|
const character = text.charAt(cursor);
|
|
if (characters instanceof RegExp) {
|
|
if (!characters.test(character)) {
|
|
return cursor;
|
|
}
|
|
} else if (!characters.includes(character)) {
|
|
return cursor;
|
|
}
|
|
cursor++;
|
|
}
|
|
return cursor;
|
|
};
|
|
}
|
|
|
|
const skipWhitespace = skip(/\s/);
|
|
const skipSpaces = skip(" \t");
|
|
console.log(skipWhitespace(" \t hi", 0));
|
|
console.log(skipSpaces(" \t hi", 0));
|
|
console.log(skipWhitespace("abc", 0));
|
|
|
|
const table = new Map<string, RegExp>([
|
|
["lf", /\n/],
|
|
["crlf", /\r\n/],
|
|
]);
|
|
const re: RegExp | undefined = table.get("lf");
|
|
if (re !== undefined) {
|
|
console.log(re.source, re.test("a\nb"));
|
|
}
|
|
console.log(table.get("nope") === undefined, table.size);
|
|
console.log("done");
|