I am trying to minify my angular-js code using js-minify tool but its throwing an exception as Error: Unexpected token: operator (>)
-
2Please provide more detailsRohit Rane– Rohit Rane2016-03-31 12:54:51 +00:00Commented Mar 31, 2016 at 12:54
-
I have an angularjs file app.js. I want to minify the file and load in server. So i used a tool javascript minifier and pasted the code there but its throwing error Error: Unexpected token: operator (>) in this line "var equityTotal = scope.chartData.length != 0 ? scope.chartData[0].reduce((a, b) => a + b, 0) : 0;" but there is no error in the code asapsaikat mukherjee– saikat mukherjee2016-03-31 13:02:12 +00:00Commented Mar 31, 2016 at 13:02
-
1The arrow function expression is a new feature introduced in ECMAScript 2015. Does the minifier have support for it?henrikmerlander– henrikmerlander2016-03-31 14:01:54 +00:00Commented Mar 31, 2016 at 14:01
-
Ya i found the problem. I reframed the function removing the arrow function and it worked. Thanks a lot!!saikat mukherjee– saikat mukherjee2016-04-01 07:47:49 +00:00Commented Apr 1, 2016 at 7:47
Add a comment
|
2 Answers
The arrow function expression is a new feature introduced in ECMAScript 2015. Your minifier probably does not support it yet. You mentioned that you were trying to do this:
scope.chartData[0].reduce((a, b) => a + b, 0)
You can rewrite it without the arrow function like this:
scope.chartData[0].reduce(function(a, b) {
return a + b
}, 0)
Comments
Why don't you use a transpiler like https://babeljs.io/ to compile your es6 code down to es5 and than minify/uglify your source code.
In this way you can continue to enjoy writing code in es6.
1 Comment
Ilia Ross
Just put your code in here babeljs.io/repl and it will converted to the desired format.