mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-05 08:13:06 +08:00
A callback that declares no element parameter, or binds it to a name that appears nowhere else in the function (`filter(() => true)`, `map((_, i) => i)`, `reduce((s, v) => s + 1, 0)`), no longer gets the element read and converted for each visit. The helpers and the fused loops pass a constant of the parameter's type in its place (NaN, "", false, or the undefined arm of a union that has one); other parameter types keep the read. An array holding an element its type cannot hold, written through an unknown[] view, threw a TypeError at that element for every callback method. With such callbacks it now behaves as in Node: - map, flatMap, forEach, some, every, findIndex, findLastIndex, reduce and reduceRight visit it without reading it; - filter appends each kept element as it is stored, so the written value stays in the result as the view's push would store it; - find and findLast read the element only once the predicate holds. Callbacks that read the element keep the TypeError for a value their parameter type cannot hold.