简体   繁体   English

从箭头功能(es6)到ES5

[英]From ARROW function (es6) to ES5

in my angularjs app I use esprima.js validation with gulp. 在我的angularjs应用中,我对gulp使用esprima.js验证。 And now, esprima throw me error for this two piece of js. 而现在,esprima对这两个js抛出了错误消息。

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

Error: Line 38843: Unexpected identifier 错误:行38843:意外的标识符

This is first piece 这是第一篇

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

and second is filter for sum 第二个是求和的过滤器

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 is "version": "4.0.0" and I found for instanbul dependecy that i need to get version "istanbul": "^1.0.0-alpha.2" , and i manually change to version 1.0.0-alpha.2 and call npm i esprima . Esprima的版本为"version": "4.0.0" ,我发现要获得即时的依赖 ,我需要获取版本"istanbul": "^1.0.0-alpha.2" ,然后我手动更改为1.0.0-alpha.2版本1.0.0-alpha.2并致电npm i esprima I do this, but same error is throw. 我这样做,但是抛出相同的错误。

Is there someone who know how to fix this? 是否有人知道如何解决此问题?

I recommend to use BabelJS ( https://babeljs.io/ ). 我建议使用BabelJS( https://babeljs.io/ )。

Babel is a compiler that will convert every "new" features to "old" ES5 code (target-level is configurable, but I guess in most cases ES5 is fine) Babel是将所有“新”功能转换为“旧” ES5代码的编译器(目标级别是可配置的,但我想在大多数情况下ES5都可以)

They even have an online Tool to try it out live ( https://babeljs.io/repl/ ) 他们甚至都有在线工具可以现场试用( https://babeljs.io/repl/

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

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