Skip to content

Mangling named functions in strict mode can cause syntax errors in Safari #179

@markmevans

Description

@markmevans

In strict mode, Safari 6.0.3 on OS X 10.8.3 raises an exception if a named function's name is the same as one of the function's argument names (at least in some scenarios). For example:

$ cat <<EOF | ./bin/uglifyjs -  --mangle
> "use strict";
> 
> function f1() {
>   return function f2(a,b,c) {
>   }
> }
> EOF

results in the following code:

"use strict";function f1(){return function n(n,t,u){}}

Safari parses the original code without errors, but the generated code causes the following error:

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

Manually converting the inner function to be anonymous or renaming to something not matching an argument's name resolves the problem.

Also, the generated code runs fine in Chrome and Firefox and Safari does not raise a syntax error for functions declared globally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions