-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
CoffeeScript 2.7.0
Expected Behavior:
The compiler should recognize and properly process function literals when they are used as arguments in a function call, especially when these function literals are not the last argument.
Actual Behavior:
The compiler throws a syntax error at the comma following the function.
How to reproduce :
foo(() => 1, 2)
# bug.coffee:2:13: error: unexpected ,
# foo(() => 1, 2)
# ^ direct equivalent works fine in javascript :
foo(() => 1, 2)Syntax ambiguity ?
Since object literal braces a: 'a', b: 'b' can be omitted if shorthands properties are used a, b then we can't know if the intent was to pass an object literal with shorthand props a, b or several arguments a, b.
An object literal with braces and shorthand props: foo(() => { 1, 2 }) transpiles to foo(() => { return {1: 1, 2: 2}; }); as expected.
So, wouldn't it be neater if the currently broken foo(() => 1, 2) didn't throw a syntax error, but picked an opiniated default ?
I'd rather write foo(() => {1, 2}) than foo((() => 1), 2) :/
btw foo(() => {1, 2}, 3) doesn't work either. 'unexpected ,'
best workaround for now
this works fine but can't take arguments
foo((-> 1), 2)
foo((=> 1), 2)alternatively add a line return after the ,
foo(
() => 1,
2
)
# transpile to javascript as expected
foo(() => {
return 1;
}, 2);