mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-26 06:34:20 +08:00
34 lines
881 B
JavaScript
34 lines
881 B
JavaScript
// The evolving-array declaration idiom (test/common's leakedGlobals
|
|
// ledger): a JS `const leaked = []` types by its LATER pushes, so the
|
|
// binding rides the checked-dynamic array — pushes land in the DOM,
|
|
// typed exits validate back out, and the function's evolved return type
|
|
// agrees with what callers read.
|
|
'use strict';
|
|
function collect() {
|
|
const leaked = [];
|
|
for (const v of ['alpha', 'beta', 'gamma']) {
|
|
if (v !== 'beta') {
|
|
leaked.push(v);
|
|
}
|
|
}
|
|
return leaked;
|
|
}
|
|
const out = collect();
|
|
console.log(out.length);
|
|
console.log(out.join(', '));
|
|
console.log(out.length > 0 ? 'leaked' : 'clean');
|
|
|
|
// The number flavor, and an empty-forever ledger.
|
|
function nums() {
|
|
const acc = [];
|
|
acc.push(1);
|
|
acc.push(2);
|
|
return acc;
|
|
}
|
|
console.log(JSON.stringify(nums()));
|
|
function never() {
|
|
const empty = [];
|
|
return empty;
|
|
}
|
|
console.log(never().length);
|