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

Destructuring and spread operator: Unexpected token .. #116

Closed
rocketraman opened this issue Mar 30, 2015 · 4 comments
Closed

Destructuring and spread operator: Unexpected token .. #116

rocketraman opened this issue Mar 30, 2015 · 4 comments
Labels

Comments

@rocketraman
Copy link

I am using espree via eslint 0.18.0 with eslint-react-plugin 2.0.1. During parsing, espree returns Unexpected token .. with a JSX spread operator:

spread.js:

let { aprop, ...other } = this.props

.eslintrc:

{
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  },
  "ecmaFeatures": {
    "modules": true,
    "jsx": true,
    "destructuring": true,
    "spread": true,
    "arrowFunctions": true,
    "blockBindings": true
  },
  "rules": {
    "strict": [2, "global"],
  }
}
$ eslint spread.js

spread.js
  1:14  error  Unexpected token ..
$ eslint --version
v0.18.0
$ grep "version" node_modules/eslint-plugin-react/package.json
  "version": "2.0.1",
$ node_modules/eslint/node_modules/.bin/esparse --version
ECMAScript Parser (using espree version 1.12.3 )
@rocketraman rocketraman changed the title Destructuring and spread operator not parsed Destructuring and spread operator: Unexpected token .. Mar 30, 2015
@steadicat
Copy link

I was just about to post this. Here's a simple test case:

var espree = require("espree");

espree.parse('var {...rest} = {};', {
  "ecmaFeatures": {
    "destructuring": true,
    "spread": true,
  },
});

Object spread is a common React pattern that has been proposed for inclusion in ES7.

Babel has experimental support for it, but Eslint doesn't support it. Support in Eslint was requested in eslint/eslint#1761, but it's blocked on Espree.

This seems to be the final feature needed to fully support React codebases.

@nzakas
Copy link
Member

nzakas commented Mar 30, 2015

We only support JSX as defined in the spec: http://facebook.github.io/jsx/

The spread object operator isn't part of ES6, and isn't part of the JSX spec outside of JSX elements. You can already use this inside of JSX attributes with Espree:

var foo = <bar {...props}/>;

That's the extent to which we're going to support it in Espree until it's ratified in some standard.

@nzakas nzakas closed this as completed Mar 30, 2015
@EvHaus
Copy link

EvHaus commented Apr 7, 2015

+1

This is currently a deal-breaker for using ESLint on React projects since the spread attribute is very pervasive in React code-bases.

Are there any workarounds?

EDIT Looks like using the babel-eslint parser works as a workaround.

@nzakas
Copy link
Member

nzakas commented Apr 7, 2015

Sorry, we are not implementing this for reasons already explained. You are free to use babel-eslint or esprima-fb with ESLint if you need to support this feature.

@eslint eslint locked and limited conversation to collaborators Apr 7, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants