Support for spread operator in JSX (without ES6)
See original GitHub issueUsing the spread operator in JSX should work in any ecma version, but instead you must set the version to 6 (or higher).
Spread is part of the JSX spec: http://facebook.github.io/jsx/ And is supported in JSX by other libraries, such as babel (with babel-preset-react). Acorn has an official plugin that supports this: https://github.com/RReverser/acorn-jsx And espree’s readme has an example, having support for spread in ES5: https://github.com/eslint/espree
Using eslint --init
and answering yes to React & JSX generates config that does not allow the spread operator (as ecma version 6 is required, see this issue: https://github.com/eslint/eslint/issues/5608).
Note: babel (recommended parser) handles the spread operator perfectly in JSX with only babel-preset-react.
What version of ESLint are you using?
2.8.0
What parser (default, Babel-ESLint, etc.) are you using?
eslint with eslint-plugin-react
Please show your full configuration:
Rules do not appear to affect this issue. Only passes with ecma version 6 (or higher).
.eslintrc
{
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
},
"plugins": [
"react"
]
}
What did you do? Please include the actual source code causing the issue.
Using the spread operator to pass props to a JSX element with ecma version 5
<div {...this.props} />
What did you expect to happen?
This should pass the linting.
What actually happened? Please include the actual, raw output from ESLint.
error Parsing error: Unexpected token
which points to the open brace: {
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (9 by maintainers)
I don’t mind taking a look if someone can point me in the right direction. 😃
This may be an issue with the Acorn plugin that Espree uses, as we delegate to that for parsing JSX. In any event, this should be a bug on Espree.
@kaicataldo that’s for experimental object rest/spread and shouldn’t be used by JSX.
@JakeSidSmith experimental rest/spread flag isn’t used for JSX parsing at all.