2

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?

Haji
  • 1,715
  • 7
  • 25
  • 41
  • What does the body of that function look like? – Blender Jul 28 '13 at 06:31
  • @Blender apparently I had a bad character hiding somewhere (see http://stackoverflow.com/questions/12719859/syntaxerror-unexpected-token-illegal). I still can't explain why the var-function change solved it, but anyway - removing a bad character fixed it. Thanks. – Haji Jul 28 '13 at 09:22

1 Answers1

2

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.

Haji
  • 1,715
  • 7
  • 25
  • 41