Apparently whenever an inner arrow function has a parenthesised parameter list, a parse error is thrown. This is a minimal reproduction; real code is likewise affected:
In the REPL of the Bangle emulator:
>x=>(y)=>0
Uncaught SyntaxError: Got => expected EOF
at line 1 col 7
x=>(y)=>0
^
>
The parser is thus not supposed to commit early to whether “(…” starts an expression or an arrow function, whether or not we are already inside an arrow function. And, indeed, other interpreters I've tried have no such problem.
There is of course a workaround, to use full function syntax for the inner function, but (and here I cannot intuit what is going wrong), parenthesising the inner function does not work, producing any of a variety of strange errors.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Apparently whenever an inner arrow function has a parenthesised parameter list, a parse error is thrown. This is a minimal reproduction; real code is likewise affected:
In the REPL of the Bangle emulator:
But per https://262.ecma-international.org/12.0/#prod-AssignmentExpression
AssignmentExpression: … | ArrowFunction | …;
ArrowFunction: ArrowParameters => ConciseBody;
ArrowParameters: BindingIdentifier | CoverParenthesizedExpressionAndArrowParameterList;
BindingIdentifier: Identifier | …;
CoverParenthesizedExpressionAndArrowParameterList: ( Expression ) | …;
ConciseBody: [Lookahead ≠ {] ExpressionBody | …;
ExpressionBody: AssignmentExpression;
The parser is thus not supposed to commit early to whether “(…” starts an expression or an arrow function, whether or not we are already inside an arrow function. And, indeed, other interpreters I've tried have no such problem.
There is of course a workaround, to use full function syntax for the inner function, but (and here I cannot intuit what is going wrong), parenthesising the inner function does not work, producing any of a variety of strange errors.