Jshint: ES7 Class Properties throws 'Unexpected token ='

Created on 13 Apr 2015  ·  8Comments  ·  Source: jshint/jshint

Jeff Morrison's stage 0 class property initializers proposal fills the void of property composition on classes.

Currently when using:

class Person {
  firstName = 'John'; // jshint error 'Unexpected token ='
  static lastName = 'Doe';
}

console.log(new Person().firstName); // "John"
console.log(Person.lastName); // "Doe"

Any plans to support such feature? Or maybe I'm missing an option? Thanks!

Most helpful comment

Just an update, it's at stage 2 now: https://github.com/tc39/proposals. Perhaps time to re-open this issue?

All 8 comments

It would be unwise for JSHint to commit to supporting any stage 0 proposals.

You can prevent the error by demarcating non-standard portions with an ignoreDelimiter:

class Person {
  //start-non-standard
  firstName = 'John';
  static lastName = 'Doe';
  //end-non-standard
}

.jshintrc

...
ignoreDelimiters: [
  { start: "start-non-standard", end: "end-non-standard" },
],
esnext: true
...

@rwaldron thanks!

@voronianski you're welcome!

It's up to stage 1 now: https://github.com/jeffmo/es-class-static-properties-and-fields
I know that's still not very far along, but I would love to use this without littering my code with start-non-standards in every class!

@hackel In the time since this feature request was made, we've formalized our requirements for new language features:

http://jshint.com/blog/new-lang-features/

We'll be happy to accept patches once the "class properties" proposal reaches stage 2!

Just an update, it's at stage 2 now: https://github.com/tc39/proposals. Perhaps time to re-open this issue?

Now that this proposal has reached stage 2, I have created an issue to track support within JSHint. See gh-3139.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Niggler picture Niggler  ·  4Comments

NemoStein picture NemoStein  ·  7Comments

Daniel-Hug picture Daniel-Hug  ·  3Comments

strugee picture strugee  ·  8Comments

stefanuddenberg picture stefanuddenberg  ·  7Comments