晚上好!我整理我的代码并在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作为解析器之外,还要努力找到在线解决方案。

谢谢 :-)

最佳答案

您应该将contextTypes放在类之外。

例:

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

Transactions.contextTypes = {
    router: PropTypes.object
}

关于javascript - 导致ESLint解析错误的ES7静态:意外 token =,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39809752/

10-17 02:24