Loren
Loren

Reputation: 14856

How to format function definition with arguments on multiple lines?

I'd like to put arguments on different lines, but I get parse errors on all the variations I try, including adding commas, allwin-style parens, and different indentations.

  constructor: (
    @a
    @b
    @c
  ) ->

Upvotes: 14

Views: 4608

Answers (2)

matyr
matyr

Reputation: 5774

Try:

constructor:\
( @a
, @b
, @c
) ->

Both trailing \ and leading , suppress newlines in CoffeeScript.

Upvotes: 26

Brian Genisio
Brian Genisio

Reputation: 48137

It appears you are out of luck. If you look at the grammar rules for the function definition, you will see that the rule is defined as:

'PARAM_START ParamList PARAM_END FuncGlyph Block'

The rule for Block allows for TERMINATOR tokens (which are semi-colon or carriage return) but the ParamList rule (the one you are interested in adding a new line in) does not allow for it.

Upvotes: 1

Related Questions