javascript - How to enable `eslint` to parse spread operator? - Stack Overflow

I am using eslint for a javascript project. eslint failed to parse spread operator and I got this error

I am using eslint for a javascript project. eslint failed to parse spread operator and I got this error 11:18 error Parsing error: Unexpected token ...

The code for above error is:

return { ...render }

The eslint configuration is yml file:

env:
  browser: true
  es6: true
extends: 'eslint:remended'
parserOptions:
  ecmaVersion: 2017
  sourceType: module
  experimentalObjectRestSpread: true
rules:
  indent:
    - error
    - 4
  linebreak-style:
    - error
    - unix
  quotes:
    - error
    - single
  semi:
    - error
    - always
  no-console:
    - off
  prefer-spread: "error"

I am using eslint for a javascript project. eslint failed to parse spread operator and I got this error 11:18 error Parsing error: Unexpected token ...

The code for above error is:

return { ...render }

The eslint configuration is yml file:

env:
  browser: true
  es6: true
extends: 'eslint:remended'
parserOptions:
  ecmaVersion: 2017
  sourceType: module
  experimentalObjectRestSpread: true
rules:
  indent:
    - error
    - 4
  linebreak-style:
    - error
    - unix
  quotes:
    - error
    - single
  semi:
    - error
    - always
  no-console:
    - off
  prefer-spread: "error"
Share Improve this question edited Jan 19, 2019 at 4:51 Ry- 225k56 gold badges492 silver badges498 bronze badges asked Jan 19, 2019 at 4:39 Joey Yi ZhaoJoey Yi Zhao 42.7k87 gold badges353 silver badges659 bronze badges 1
  • Which version of ESLint are you using? – Ry- Commented Jan 19, 2019 at 4:52
Add a ment  | 

2 Answers 2

Reset to default 6

This is related to ESLint doesn't support spread operator in objects #10307, where full description of various alternatives on how to fix it is listed.

Essentially it boils down to changing to ecmaVersion: 2018 (or the equivalent ecmaVersion: 9), which is when it first was officially supported. With this change there is also no need for the experimentalObjectRestSpread: true any more.

The issue is fixed by add configuration: parser: 'babel-eslint'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742323593a4422306.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信