mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-08 08:44:37 +08:00
A function expression stored in a function type with more parameters folds `arguments.length` to that type's parameter count, the count every call through the slot passes. A named expression that calls itself through its own name passes only its declared parameters there, so no constant answers both calls. Such a read now reports SC1090 with the reason, and expressions that do not refer to their own name keep the fold.
9 lines
426 B
TypeScript
9 lines
426 B
TypeScript
// `arguments.length` in a function expression stored in a slot with more
|
|
// parameters counts that slot's arguments, but a call through the
|
|
// expression's own name passes only the declared ones: no constant answers
|
|
// both, so the read fences.
|
|
const count: (a: number, b: number) => number = function self(a: number): number {
|
|
return a > 0 ? self(a - 1) + arguments.length : arguments.length;
|
|
};
|
|
console.log(count(2, 0));
|