4

I am trying to minify my angular-js code using js-minify tool but its throwing an exception as Error: Unexpected token: operator (>)

4
  • 2
    Please provide more details Commented 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 asap Commented Mar 31, 2016 at 13:02
  • 1
    The arrow function expression is a new feature introduced in ECMAScript 2015. Does the minifier have support for it? Commented 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!! Commented Apr 1, 2016 at 7:47

2 Answers 2

4

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)
Sign up to request clarification or add additional context in comments.

Comments

1

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

Just put your code in here babeljs.io/repl and it will converted to the desired format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.