Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newlines in function arguments or parenthesis enclosed blocks #325

Open
arkarkark opened this issue Aug 5, 2014 · 7 comments
Open

newlines in function arguments or parenthesis enclosed blocks #325

arkarkark opened this issue Aug 5, 2014 · 7 comments

Comments

@arkarkark
Copy link

arkarkark commented Aug 5, 2014

the following code (bad.coffee) is parsed by the original coffee but not CoffeeScriptRedux

angular.module('App').controller('AppController',
['$location', '$scope', (
  $location,   $scope) ->

  @link = (field) ->
    ("http://example.com" +
     "/" + field)
  @
])

if I modify it to this (good.coffee) it works

angular.module('App').controller('AppController',['$location', '$scope', (  $location,   $scope) ->

  @link = (field) ->
    ("http://example.com" +     "/" + field)
  @
])

I can't tell if this is #119 or #142 related so apologies if it's a dupe.

I installed from npm

$ ./bin/coffee -v
CoffeeScript version 2.0.0-beta8
$ ./bin/coffee -js < ~/mysrc/third_party/bad.coffee
Syntax error on line 1, column 50: unexpected '\n' (\u000A)
1 : angular.module('App').controller('AppController',
^ :~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
2 : ['$location', '$scope', (
3 :   $location,   $scope) ->
4 :

and the original CoffeeScript

$ coffee -v
CoffeeScript version 1.7.1
$ coffee -p ~/mysrc/third_party/bad.coffee
(function() {
  angular.module('App').controller('AppController', [
    '$location', '$scope', function($location, $scope) {
      this.link = function(field) {
        return "http://example.com" + "/" + field;
      };
      return this;
    }
  ]);

}).call(this);

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/3560984-newlines-in-function-arguments-or-parenthesis-enclosed-blocks?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).
@yumitsu
Copy link

yumitsu commented Aug 12, 2014

Your code looks bad for me too. Anyway, if I modify your code just for a bit:

angular.module('App').controller('AppController', [
  '$location', '$scope', (
    $location,   $scope) ->

    @link = (field) ->
      ("http://example.com" +
      "/" + field)
    @
])

CoffeeScriptRedux compiles it as expected:

// Generated by CoffeeScript 2.0.0-beta8
angular.module('App').controller('AppController', [
  '$location',
  '$scope',
  function ($location, $scope) {
    this.link = function (field) {
      return 'http://example.com' + '/' + field;
    };
    return this;
  }
]);

@arkarkark
Copy link
Author

indeed, but if it's valid for the original coffee compiler, shouldn't your compiler like it too?

@yumitsu
Copy link

yumitsu commented Aug 12, 2014

@arkarkark Honestly, I can't understand why vanilla coffee-script acts so "forgiving".

@arkarkark
Copy link
Author

:-D

@flying-sheep
Copy link

OK, so why is this invalid?

a(b,
  c)

→ Syntax error on line 1, column 5: unexpected '\n' (\u000A)

isn’t the grouping given via parens?

it’s especially of interest for me because coffee-react-transform creates such code:

Car = React.createClass
  render: ->
    React.createElement(Vehicle, {"doors": (4), "locked": (isLocked()), "data-colour": "red", "on": true},
      React.createElement(Parts.FrontSeat, null),
      React.createElement(Parts.BackSeat, null),
      React.createElement("p", {"className": "seat"}, "Which seat can I take? ", (@props?.seat or 'none'))
    )

@SuperPaintman
Copy link

@flying-sheep

a(b
   ,c)

# or

a \
      b
    , c

@flying-sheep
Copy link

thanks but:

  1. i didn’t create the code, coffee-react-transform did, so i have no control over it.
  2. there’s absolutely no ambiguity so there’s no reason why it shouldn’t be accepted
  3. the grammar says nothing about whitespace in argument lists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants