简体   繁体   English

StandardJS linting返回静态变量的解析错误

[英]StandardJS linting returns parsing error for static variable

I do get an Parsing error: Unexpected token linting error for this line using standardJS. 我确实收到Parsing error: Unexpected token使用standardJS出现了此行的 Parsing error: Unexpected token掉毛错误。 Therefore my CI is failing. 因此,我的CI失败了。

I don't understand what is wrong with this line. 我不明白这行有什么问题。 How could I fix this? 我该如何解决?

export default (App) => {
  return class Apollo extends React.Component {
    static displayName = 'withApollo(App)' // <--
    static async getInitialProps (ctx) {
    // ...
  }
}

If this is standard javascript then the error is that classes can only contain functions, not properties. 如果这是标准javascript,则错误是类只能包含函数,不能包含属性。

The correct syntax should be: 正确的语法应为:

class Apollo extends React.Component {
  static async getInitialProps (ctx) {
  // ...
}

Apollo.displayName = 'withApollo(App)';

export default (App) => {
  return Apollo;
}

If you are using the proposed (but not yet implemented or approved) ES7/ES8 class properties then maybe eslint does not support it yet. 如果您使用的是提议的(但尚未实施或批准)ES7 / ES8类属性,那么eslint可能eslint支持。


If, unlike the original question, you need to use the App parameter, Just do it in the function you want to export: 如果与原始问题不同,如果您需要使用App参数,则只需在要导出的函数中进行操作即可:

class Apollo extends React.Component {
  static async getInitialProps (ctx) {
  // ...
}

export default (App) => {
  Apollo.displayName = `withApollo(${App})`;
  return Apollo;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM