mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-03 07:54:40 +08:00
tests/coverage-fixtures/mixed.ts used `const { length: firstItem } = items`
as its SC1031 example. Object patterns of positions and length over arrays
compile now, so coverage counted 13/13 static. The example now destructures
a union source (array | string), which keeps the SC1031 object-pattern fence
at the same line and column; only the message's source kind changes, from
array-typed to union-typed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18 lines
573 B
TypeScript
18 lines
573 B
TypeScript
function score(n: number): number {
|
|
let total = 0;
|
|
for (let i = 0; i < n; i++) {
|
|
total += i % 3 === 0 ? 2 : 1;
|
|
}
|
|
return total;
|
|
}
|
|
const items = [1, 2, 3];
|
|
const handler = (x: number) => x * 2;
|
|
|
|
const anyone: unknown = score(1);
|
|
const flags = anyone == score(2); // unknown/object coercion keeps the fence; static primitive pairs lower
|
|
const { length: firstItem } = score(3) > 99 ? items : "abc"; // a union source keeps the object-pattern fence (narrow first)
|
|
let label = "score: ";
|
|
label += score(10);
|
|
console.log(label);
|
|
console.log(items.length, handler(2));
|