静态类属性不与Babel一起使用 [英] static class property not working with Babel
问题描述
我正在使用JSDOC,所有它支持npm插件来创建漂亮的文档。 jsdoc正在运行并解析JSX文件时遇到困难,它总是抛出错误,如下所示 =
sign
I am using JSDOC and all it supported npm plugins to create nice documentation. Getting hard time when jsdoc is running and parsing JSX file it always throws error as below near =
sign
SyntaxError: unknown: Unexpected token
export default class SaveDesign extends Component {
static displayName = 'SaveDesign';
}
conf.json file
conf.json file
{
"source": {
"include": [ "src/app/test.js", "src/app/components/Modals/Template/SaveDesign.jsx"],
"exclude": [ "src/fonts", "src/icons", "src/less", "src/vector-icon" ],
"includePattern": ".+\\.js(doc|x)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"plugins": ["node_modules/jsdoc-babel"],
"babel": {
"extensions": ["js", "es6", "jsx"],
"presets": ["es2015"]
},
"jsx": {
"extensions": ["js", "jsx"]
}
}
推荐答案
类属性不属于ES2015规范,因此它们也不属于ES2015 Babel预设。 向该语言添加类属性的提议目前处于标准化的第二阶段过程,所以你需要第2阶段预设。
Class properties aren't part of the ES2015 spec, so they're not part of the ES2015 Babel preset either. The proposal to add class properties to the language is currently at Stage 2 of the standardization process, so you need the Stage 2 preset.
https://babeljs.io/docs/plugins/preset-stage-2/
或者,你可以安装这个课程属性插件本身:
Alternatively, you could just install the class properties plugin on its own:
http://babeljs.io/docs/plugins/transform-class-properties/
这篇关于静态类属性不与Babel一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!