mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
fieldedErrorReason checked each field of a fielded error class with a fresh inspectSupport walk, so a field typed as the class itself (`next: Chain`) recursed until the compiler's stack overflowed. It now continues the caller's walk, where the class is a recursive shape. The fielded error helper then rendered a cycle by expanding it to the depth budget, where Node prints `<ref *1>` and `[Circular *1]`. Classes whose fields reach the class or one of its bases now run the circular machinery other cycle-capable objects use (circCheck before the depth answer, seenPush, refWrap), which also covers a cycle through a base-typed field of a subclass. New corpus program 6526-error-subclass-cycles.ts. 6187-js-match-or-empty-array.js compiles without its deferred fence now that the match-or-empty union reads through its widened members: the `@deferred-fences: 1` header goes, and the program calls the function the fence used to cover.
21 lines
698 B
JavaScript
21 lines
698 B
JavaScript
// `s.match(re) || []` types the empty array as an empty tuple that the
|
|
// typescript-go API panics to describe (moment.js's configFromStringAndFormat).
|
|
// The union reads through its widened members, so the whole program
|
|
// compiles, including the statements whose lowering asks about that type.
|
|
|
|
/** @param {string} s */
|
|
function firstDigit(s) {
|
|
return (s.match(/\d/) || [])[0];
|
|
}
|
|
|
|
/** @param {string} s */
|
|
function digitCount(s) {
|
|
let count = 0;
|
|
for (const ch of s) if (ch >= '0' && ch <= '9') count++;
|
|
return count;
|
|
}
|
|
|
|
const parsers = { firstDigit, digitCount };
|
|
console.log(typeof parsers.firstDigit, parsers.digitCount('a1b22'));
|
|
console.log(firstDigit('a1b22'), firstDigit('none'));
|