mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
URLSearchParams crossing an implicit ToString (`${sp}`, "" + sp, String(sp))
had no lowering: ensureString now answers sp.toString, the serialized pair
list. Record inits also accept shorthand members (`new URLSearchParams({ model })`)
like the explicit `{ model: model }` spelling.
`re.exec(s)?.index` keeps the optional chain: the read is the match row's
index/input member (the chain lowering binds the guarded receiver first),
so the questionDotToken guard no longer diverts it.
Array.from(s) over a string whose binding the checker narrowed through a
guard read as the narrowed union and fenced; the site type now decides, and
the read is coerced to that string (code points, fresh array).
Corpus 8423-8425 pin all three against Node.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
757 B
TypeScript
20 lines
757 B
TypeScript
// Array.from over a string the checker narrowed through a guard, and over
|
|
// code points (surrogate pairs stay whole), each a fresh array.
|
|
const values: (string | undefined)[] = ["abc", undefined, "a\u{1F600}b"];
|
|
for (const value of values) {
|
|
if (value === undefined) {
|
|
console.log("skip");
|
|
continue;
|
|
}
|
|
const chars = Array.from(value);
|
|
console.log(chars.length, chars.join("|"));
|
|
}
|
|
const maybe: string | undefined = "xy";
|
|
if (maybe !== undefined) console.log(Array.from(maybe).length);
|
|
const plain: string = "q";
|
|
console.log(Array.from(plain), Array.from(plain).length);
|
|
function guarded(v: string | undefined): boolean {
|
|
return v !== undefined && Array.from(v).length > 1;
|
|
}
|
|
console.log(guarded("ab"), guarded("a"), guarded(undefined));
|