I'm using r.js to optimize/uglify my JavaScript code which is using RequireJS.
One of my modules is a polyfill module:
define(function(){
if (!Array.prototype.filter)
{ /* ... */ }
var isPolyfillNeeded = function () { /* ... */ }
if (isPolyfillNeeded()) {
/* polyfill implementation */
}
});
The module causes parsing error thrown from r.js when trying to uglify it, saying:
Tracing dependencies for: ../scripts/main-app
Error: Parse error using UglifyJS for file: C:/.../polyfill.js
Unexpected character '?' (line: .., col: .., pos: ..)
undefined
In module tree:
../scripts/main-main-app
moduleA
moduleB
When replacing var isPolyfillNeeded = function ()
with function isPolyfillNeeded()
, it works fine.
Why is that?
The problem was a bad character that was hiding somewhere in my code, as I copy pasted from some snippet. It was invisible so it was hard to spot.