我正在使用JSDOC及其所有受支持的npm插件来创建漂亮的文档。当jsdoc运行并解析JSX文件时越来越麻烦,它总是在=
符号附近抛出以下错误
SyntaxError: unknown: Unexpected token
export default class SaveDesign extends Component {
static displayName = 'SaveDesign';
}
conf.json文件
{
"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预设。 The proposal to add class properties to the language当前处于标准化过程的第3阶段,因此您需要第3阶段预设。
https://babeljs.io/docs/plugins/preset-stage-3/
或者,您可以仅安装类属性插件:
https://babeljs.io/docs/en/babel-plugin-proposal-class-properties
关于javascript - 静态类属性无法与Babel一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40367392/