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>
24 lines
475 B
JavaScript
24 lines
475 B
JavaScript
// Basic: no params, expression body
|
|
var f1 = () => 42;
|
|
console.log(f1());
|
|
|
|
// Single param without parens
|
|
var f2 = x => x + 1;
|
|
console.log(f2(10));
|
|
|
|
// Multi params
|
|
var f3 = (a, b) => a + b;
|
|
console.log(f3(3, 4));
|
|
|
|
// Block body with return
|
|
var f4 = (x) => { return x * 2; };
|
|
console.log(f4(5));
|
|
|
|
// Arrow as callback argument
|
|
function apply(fn, val) { return fn(val); }
|
|
console.log(apply(x => x * 3, 7));
|
|
|
|
// typeof arrow function
|
|
var f5 = () => 1;
|
|
console.log(typeof f5);
|