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

Add support for comma in function call and function declaration after the last argument (re-submitted) #286

Closed
jrencz opened this issue Jul 27, 2016 · 5 comments

Comments

@jrencz
Copy link

jrencz commented Jul 27, 2016

This is a re-submission of #208


I'd like to give an example with AngularJS-centerd code, where function arguments have different meaning then the rest of JS world.

To ensure the diff to be as meaningful as possible I'd like to be able to declare dependency injection arguments line-by-line and make sure adding another won't modify the line history on any other line than the one I'm adding/modifying:

angular.module('myModule', []).service('myService', function (
  dependencyService1,
  dependencyService2,
  dependencyService3
) {
  // service logic
})

(I'm not using array DI syntax for the sake of brevity)

If I want to add fourth dependency as the last argument (I'd probably do exactly that if I want my dependencies to be organised alphabetically or by some custom logic - whatever) I get this:

angular.module('myModule', []).service('myService', function (
  dependencyService1,
  dependencyService2,
  dependencyService3, // changed line: added comma
  dependencyService4 // added line
) {
  // service logic
})

With last comma the example looks almost exactly the same:

angular.module('myModule', []).service('myService', function (
  dependencyService1,
  dependencyService2,
  dependencyService3, // please notice the last comma
) {
  // service logic
})
angular.module('myModule', []).service('myService', function (
  dependencyService1,
  dependencyService2,
  dependencyService3, // please notice: no change in this line
  dependencyService4, // added line: the change I've made is a one-liner, by diff is more meaningful!
) {
  // service logic
})

What I'd like to do is to be able to use last comma syntax and still use eslint, but it's not possible since code using commas after last function argument are not parsed by espree yet.

Line 5: Unexpected token 

I know this syntax is not yet production ready, but for transpilers (namely: babel) stripping this one comma is not a problem

@ljharb
Copy link
Sponsor Contributor

ljharb commented Jul 27, 2016

Repeating my comment from #208 (comment):
This proposal advanced today to stage 4 at the July TC39 meeting (tc39/proposals@6826a19), which means it's past time to support it :-)

@nzakas
Copy link
Member

nzakas commented Jul 29, 2016

It actually means it's the start of time when we can support it. :) Remember, we don't do anything until it's stage 4.

I'm waiting to hear back on what Acorn's position is on this: acornjs/acorn#441

@nzakas
Copy link
Member

nzakas commented Jul 29, 2016

I started work on this and trailing commas turned out to be pretty easy. This is the Acorn fork I'm using: https://github.com/nzakas/acorn/tree/issue441

Just need to wait to hear back on Acorn's position.

@SimenB
Copy link

SimenB commented Sep 14, 2016

This was merged into acorn a week ago 😄 acornjs/acorn#461

@nzakas
Copy link
Member

nzakas commented Sep 14, 2016

Work to integrate Acorn is happening here: #287

@nzakas nzakas closed this as completed Sep 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants