mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
* Fix nested mutual function recursion - Predeclare nested function bindings before sibling closures capture them. - Cover two- and three-way recursive declaration cycles across native backends. Fixes #32 Co-authored-by: ryoppippi <1560508+ryoppippi@users.noreply.github.com> * Record nested recursion parity baseline - Add the generated TypeScript 7 order baseline for the nested mutual-recursion corpus fixture. Fixes #32 Co-authored-by: ryoppippi <1560508+ryoppippi@users.noreply.github.com> --------- Co-authored-by: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
39 lines
736 B
TypeScript
39 lines
736 B
TypeScript
function parity(n: number): string {
|
|
const result = even(n);
|
|
|
|
function even(k: number): string {
|
|
if (k === 0) return "even";
|
|
return odd(k - 1);
|
|
}
|
|
|
|
function odd(k: number): string {
|
|
if (k === 0) return "odd";
|
|
return even(k - 1);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
console.log(parity(8), parity(7));
|
|
|
|
function threeWay(n: number): string {
|
|
function first(k: number): string {
|
|
if (k === 0) return "first";
|
|
return second(k - 1);
|
|
}
|
|
|
|
function second(k: number): string {
|
|
if (k === 0) return "second";
|
|
return third(k - 1);
|
|
}
|
|
|
|
function third(k: number): string {
|
|
if (k === 0) return "third";
|
|
return first(k - 1);
|
|
}
|
|
|
|
return `${first(n)},${second(n)},${third(n)}`;
|
|
}
|
|
|
|
console.log(threeWay(5));
|