CoffeeScriptRedux icon indicating copy to clipboard operation
CoffeeScriptRedux copied to clipboard

Indented function arguments should be valid syntax

Open nickretallack opened this issue 12 years ago • 7 comments

This coffeescript should be valid.

a b,
  c
  d

In regular coffeescript, it generates

a(b, c, d);

But redux says:

Syntax error on line 2, column 4: unexpected '\n'
1 : a b,
2 :   c
^ :~~~~^
3 :   d
4 :

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/85521-indented-function-arguments-should-be-valid-syntax?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github).

nickretallack avatar Oct 25 '12 00:10 nickretallack

This is preventing me from moving any of my projects to Redux as I rely on a HAML-ish DSL that works perfectly fine in regular coffeescript...

Sample:

MyView = View.extend
  render: (_)->
    _ '.aDiv',
      _ '.aNestedDiv', 'some text'

peterwmwong avatar Mar 10 '13 07:03 peterwmwong

+100 for anything like this that makes line-continuations easier to use, simpler, and sane. The CS line-continuation rules are a mish-mash at the moment and not very friendly and not documented. I've given up and mostly use backslashes at the end of lines (so ugly!).

On Sat, Mar 9, 2013 at 11:15 PM, Peter Wong [email protected]:

This is preventing me from moving any of my projects to Redux as I rely on a HAML-ish DSL that works perfectly fine in regular coffeescript...

Sample:

MyView = View.extend render: (_)-> _ '.aDiv', _ '.aNestedDiv', 'some text'

— Reply to this email directly or view it on GitHubhttps://github.com/michaelficarra/CoffeeScriptRedux/issues/83#issuecomment-14677572 .

mark-hahn avatar Mar 10 '13 08:03 mark-hahn

Mine too when I try running my code:

{html, css} = require "lilyturf"

page = html ->
  @div class: "new",
    @span id: "none", "x"

style = css ->
  "html":
    "css": "red"
    head:
      fontSize: 10
      color: @hsl 10, 20, 30

tiye avatar Apr 21 '13 04:04 tiye

I want this pretty sorely too; there just isn't a way that's tidy to break up arguments across multiple lines in cs-redux. The only ones I have found that are legal are somewhat hideous:

someFunc 'some really long string, object, invocation or similar',
'some other pretty long, hard-to-break-into-lines anything'

someFunc(
  'some really long string, object, invocation or similar'
  'some other pretty long, hard-to-break-into-lines anything'
)

johan avatar Aug 02 '13 19:08 johan

+1

Think about a use-case with async:

data = [0,1,2,3]

async.eachSeries data,
  (elm, cb) ->
    # do someting...
    cb()
  (err) ->
    console.log "Done"

I have this type of code all over my projects. With the current implementation, I would have to write this code like this:

data = [0,1,2,3]

iterator = (elm, cb) ->
  # do someting...
  cb()

async.eachSeries data, iterator, (err) ->
  console.log "Done"

which becomes quite hard to maintain once iterator gets longer etc.

sebastianhoitz avatar Aug 23 '13 07:08 sebastianhoitz

+1

Just tried to migrate a project from the original compiler to redux. I think I'm encountering this issue for code like this:

angular.module("foobar", ["dep1",
    "dep2"])

I get:

Syntax error on line 2, column 4: unexpected '(INDENT)' (\uEFEF)
1 : angular.module("foobar", ["dep1",
2 :     "dep2"])
^ :~~~~^
3 :
4 :

As @johan wrote, the only way around it is to skip the indentation altogether on the continuation line, but that lowers readability drastically...

provegard avatar Aug 29 '14 06:08 provegard

Correction: My case can be fixed with a backslash to explicitly indicate a continuation line, except on Windows where the CR isn't properly handled by the preprocessor. I'll open a separate issue.

provegard avatar Aug 29 '14 12:08 provegard