javascript - StandardJS linting 返回静态变量的解析错误
问题描述
使用standardJS ,我确实收到了这条线Parsing error: Unexpected token
的linting错误。因此我的 CI 失败了。
我不明白这条线有什么问题。我该如何解决这个问题?
export default (App) => {
return class Apollo extends React.Component {
static displayName = 'withApollo(App)' // <--
static async getInitialProps (ctx) {
// ...
}
}
解决方案
如果这是标准 javascript,那么错误是类只能包含函数,不能包含属性。
正确的语法应该是:
class Apollo extends React.Component {
static async getInitialProps (ctx) {
// ...
}
Apollo.displayName = 'withApollo(App)';
export default (App) => {
return Apollo;
}
如果您正在使用提议的(但尚未实现或批准)ES7/ES8 类属性,那么可能eslint
还不支持它。
如果与原始问题不同,您需要使用App
参数,只需在要导出的函数中执行即可:
class Apollo extends React.Component {
static async getInitialProps (ctx) {
// ...
}
export default (App) => {
Apollo.displayName = `withApollo(${App})`;
return Apollo;
}
推荐阅读
- python - Beautifulsoup python Howlongtobeat.com 提取元素并导出到 .csv
- javascript - 如何使用 Canvas 在 d3 v4/v5 中平移滚动
- woocommerce - 是否有所有 woocommerce webhook 操作的列表?
- javascript - chart.js:从数据库获取数据后的空甜甜圈
- node.js - 环回js中基于权限/属性的授权
- c - 为什么当我在全局范围内将 char 变量分配给 int 变量时编译器会给我错误?
- android - 未在所有设备上收到 FCM 推送通知
- javascript - componentWillReceiveProps() 中的 nextProps 没有得到状态数组 prop 的正确值
- python - 在python中增加列表的大小
- c# - .net 检查 api 响应数据 c# post request