Implement parsing, evaluation, lexical this capture, and new rejection for arrow functions. Covers expression bodies, block bodies, zero/single/ multi-param forms, and backtracking disambiguation from grouping parens. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
18 lines
480 B
JavaScript
18 lines
480 B
JavaScript
// Arrow functions can be immediately invoked (IIFE pattern).
|
|
|
|
// Basic IIFE: no params.
|
|
console.log((() => 42)());
|
|
|
|
// IIFE with a single param.
|
|
console.log((x => x * 2)(6));
|
|
|
|
// IIFE with multiple params.
|
|
console.log(((a, b) => a + b)(3, 4));
|
|
|
|
// IIFE with a block body and explicit return.
|
|
console.log(((x) => { return x * x; })(5));
|
|
|
|
// Nested IIFE: inner arrow is immediately invoked inside outer arrow body.
|
|
var result = ((a) => ((b) => a + b)(10))(5);
|
|
console.log(result);
|