0

In my Grunt/yeoman/angular project, I have part of the code written as node modules and imported by Grunt during the build project with browserify. it happens that, only on safari(checked on 7 and 8), the minified version of the webapp doesn't work because of this error:

SyntaxError: Cannot declare a parameter named 'k' in strict mode

I discovered that the line of code is this one:

c.prototype.key=function k(k){var a=this._baseState;return f(null===a.key),a.key=k,this}

And the starting code is:

Node.prototype.key = function key(key) {
  var state = this._baseState;

    assert(state.key === null);
      state.key = key;

        return this;
};

I don't understand if it is part of the browserify libraries, but surely it's included when I add mathjs to the project. I tried reserving the word "key" with uglifyJS mangle options, but "key" is a reserved word, too.

How can I avoid this kind of problems? Am I using the wrong approach?

EDIT: I found the function in asn1 lib https://github.com/indutny/asn1.js/blob/master/lib/asn1/base/node.js#L225 Now I don't really know how to go on.

EDIT: The author of the library has fixed the issue istantly :) https://github.com/indutny/asn1.js/commit/c75d861e705df9559bf572e682552278b98a218d

steeeveb
  • 35
  • 5
  • Are you sure this is part of the official Browserify libraries? If not, we need to know which library this is. – Qantas 94 Heavy Jan 27 '15 at 13:11
  • Facepalm. It is included only when I include mathjs – steeeveb Jan 27 '15 at 14:09
  • Well, I think the reason you get the syntax error is that the `key` function has a `name` property which exactly matches the argument name (both are `k` in the uglified code): `function k(k){ ... }` Unfortunately, if this is part of another library, I'm not sure how you fix this. – Jordan Kasper Jan 27 '15 at 15:33
  • Double facepalm. I knew this thing but when I have written I was not thinking to that. The only solution is to open an issue to mathjs and "friends" – steeeveb Jan 27 '15 at 17:13
  • After more digging into the generated code It seems it is part of a browserify lib included only in I include mathjs or decimal.js(its dependency), but I'm not sure, I'm trying to understand how browserify works.. – steeeveb Jan 27 '15 at 20:51
  • Wait, is this a browserify (tooling) error, or an actual runtime error in Safari? It shouldn't be. – Bergi Jan 28 '15 at 00:11
  • This sounds like a Safari bug. `function k(k) {}` is valid in both ES5 and ES6. – Bergi Jan 28 '15 at 00:24
  • 1
    You should always show the other investigations you already did: [Mangling named functions in strict mode can cause syntax errors in Safari](https://github.com/mishoo/UglifyJS2/issues/179) – t.niese Jan 28 '15 at 00:32

0 Answers0