簡體   English   中英

從箭頭功能(es6)到ES5

[英]From ARROW function (es6) to ES5

在我的angularjs應用中,我對gulp使用esprima.js驗證。 而現在,esprima對這兩個js拋出了錯誤消息。

internal/streams/legacy.js:59
  throw er; // Unhandled stream error in pipe.
  ^

錯誤:行38843:意外的標識符

這是第一篇

var filteredCampaignItems = campaignItems.filter((thing, index, self) => index === self.findIndex((t) => (
              t.expectedAdvertisementDisplayCount === thing.expectedAdvertisementDisplayCount && t.smartId === thing.smartId
            ))
          )

第二個是求和的過濾器

app.filter('sumProduct', function() {
return function (input) {
var i = input instanceof Array ? input.length : 0;
var a = arguments.length;
if (i === 0)
  return i;
var total = 0;
for(var x of input){
  var duration = parseFloat(x.meta_duration);
  if(isNaN(duration)){
      throw 'filter sumProduct can count only numeric values';
  }
  total += duration;
}
return total;
}
});

Esprima的版本為"version": "4.0.0" ,我發現要獲得即時的依賴 ,我需要獲取版本"istanbul": "^1.0.0-alpha.2" ,然后我手動更改為1.0.0-alpha.2版本1.0.0-alpha.2並致電npm i esprima 我這樣做,但是拋出相同的錯誤。

是否有人知道如何解決此問題?

我建議使用BabelJS( https://babeljs.io/ )。

Babel是將所有“新”功能轉換為“舊” ES5代碼的編譯器(目標級別是可配置的,但我想在大多數情況下ES5都可以)

他們甚至都有在線工具可以現場試用( https://babeljs.io/repl/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM