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

Unexpected token = (null) on x = {} #756

Closed
mustafawm opened this issue Jan 23, 2017 · 6 comments

Comments

@mustafawm
Copy link

commented Jan 23, 2017

Hi,

I have the following in my code:

export default class App extends React.Component {

  state = { 
    aa: {},
    bb: {},
    cc: []
  }
...

keep getting Parsing error: Unexpected token = (null) on 3:9 (the =) even when I try to ignore the warning with // eslint-disable-line or other forms of ignoring/hiding warning.

Any advice on how to ignore/pass this error, as it's blocking StandardJS from scanning the rest of the file.

@falmar

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2017

You need to put the state of the react component inside the constructor that receive a props parameter then call the super method and pass the props parameter to call the constructor of the React.Component you inherit from..

Here is an example:

export default class App extends React.Component {
  constructor (props) {
    super(props)

    this.state = {
      aa: {},
      bb: {},
      cc: {},
    }
  }

  render () {
    return <div />
  }
}

Note you need to use this like so this.state = {}

@mustafawm

This comment has been minimized.

Copy link
Author

commented Jan 23, 2017

Thanks, I know that but the team is using babel-preset-stage-2 which allows defining the state in the format I put above.

So there is no other way to ignore/skip this type?

@falmar

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2017

Ah well. I tried it out myself and yes this warning raise up. May it be that ESLint does not quite understand this feature yet?

@mustafawm

This comment has been minimized.

Copy link
Author

commented Jan 23, 2017

Thanks. Yeah, I think you're right, it is an ESLint issue.

@feross

This comment has been minimized.

Copy link
Member

commented Jan 23, 2017

standard only supports features that are stage 4 or later. If you want to use experimental language features, then you need to set a custom parser. See: https://github.com/feross/standard#can-i-use-a-custom-js-parser-for-bleeding-edge-es-next-support

@feross feross closed this Jan 23, 2017

@p4bloch

This comment has been minimized.

Copy link

commented Feb 15, 2017

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants
You can’t perform that action at this time.