ES7静态导致ESLint解析错误:意外的令牌=

时间:2016-10-01 17:53:32

标签: javascript eslint

晚上好!当我在React组件中使用以下ES7代码时,我正在使用我的代码并使用Parsing error: Unexpected token =

static contextTypes = {
    router: PropTypes.object
}

该组件是基于类的组件:

class Transactions extends Component {

我已将babel-eslint添加到我的eslintrc.json文件中:

{
  "parser": "babel-eslint",
  "plugins": [
    "react",
    "react-native"
  ],
  "ecmaFeatures": {
    "jsx": true
  },
  "extends": ["standard", "standard-react"]
}

依赖项的版本在我的package.json中设置如下:

"babel-eslint": "^6.0.4",
"eslint-plugin-babel": "^3.2.0",
"eslint-plugin-react": "^5.0.1",
"eslint": "^2.2.0",
"eslint-config-standard": "^5.1.0",
"eslint-config-standard-jsx": "^1.1.1",
"eslint-config-standard-react": "^2.3.0",
"eslint-loader": "^1.3.0",
"eslint-plugin-promise": "^1.0.8",
"eslint-plugin-react": "^4.1.0",
"eslint-plugin-standard": "^1.3.2"

任何想法都会很好,除了使用babel-eslint作为解析器之外,还在努力寻找在线解决方案。

谢谢: - )

1 个答案:

答案 0 :(得分:1)

您应该将您的contextTypes放在班级之外。

示例:

class Transactions extends Component {
   ....
   ....
}

Transactions.contextTypes = {
    router: PropTypes.object
}