簡體   English   中英

StandardJS linting返回靜態變量的解析錯誤

[英]StandardJS linting returns parsing error for static variable

我確實收到Parsing error: Unexpected token使用standardJS出現了此行的 Parsing error: Unexpected token掉毛錯誤。 因此,我的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可能eslint支持。


如果與原始問題不同,如果您需要使用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