[英]Mysterious ESLint Parsing Error
在以下代码的第4行,ESLint给我一个解析错误说:
意外的令牌=
我想知道为什么会这样? 代码运行正常。 我究竟做错了什么?
import { Component, PropTypes } from 'react';
export default class MainApp extends Component {
static propTypes = {
children: PropTypes.any.isRequired
}
componentWillMount() {
require('./styles/main.styl');
}
render() {
return (
<div>
{this.props.children}
</div>
);
}
}
我能够解决这个问题:
$ npm i --save-dev babel-eslint
要么
$ yarn add babel-eslint --dev
只需在您的.eslintrc文件中添加"parser": "babel-eslint",
即可。
示例.eslintrc使用babel-eslint
和airbnb的配置以及一些自定义规则:
{
"parser": "babel-eslint",
"extends": "airbnb",
"rules": {
"arrow-body-style": "off",
"no-console": "off",
"no-continue": "off"
}
}
你不能在类中拥有属性,只能有方法。
参考: http : //www.2ality.com/2015/02/es6-classes-final.html#inside_the_body_of_a_class_definition
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.