[英]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.