Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mangling parameter names in strict mode results in Safari Syntax Error #1202

Closed
ligaz opened this issue Jul 13, 2016 · 7 comments
Closed

Mangling parameter names in strict mode results in Safari Syntax Error #1202

ligaz opened this issue Jul 13, 2016 · 7 comments

Comments

@ligaz
Copy link

ligaz commented Jul 13, 2016

The following code:

'use strict'
var a = function n(param1) {
}

When minified with: --compress --mangle --keep-fnames
Results in:

"use strict";var a=function n(n){};

Unfortunately this breaks Safari with: SyntaxError: Cannot declare a parameter named 'n' as it shadows the name of a strict mode function.

@kzc
Copy link
Contributor

kzc commented Jul 13, 2016

The original unmodified input would have the same issue.

@ligaz
Copy link
Author

ligaz commented Jul 13, 2016

My bad, I have corrected the original code.

@kzc
Copy link
Contributor

kzc commented Jul 13, 2016

This should fix it:

--- a/lib/scope.js
+++ b/lib/scope.js
@@ -316,7 +316,7 @@ AST_Function.DEFMETHOD("next_mangled", function(options, def){
     var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
     while (true) {
         var name = AST_Lambda.prototype.next_mangled.call(this, options, def);
-        if (!(tricky_def && tricky_def.mangled_name == name))
+        if (!tricky_def || (tricky_def.mangled_name != name && tricky_def.name != name))
             return name;
     }
 });

@michaelficarra
Copy link
Contributor

This is a duplicate of #179.

@kzc
Copy link
Contributor

kzc commented Jul 13, 2016

#1202 is specific to mangle with keep_fnames=true.

By default compress and mangle use keep_fnames=false so this issue does not occur.

@kzc
Copy link
Contributor

kzc commented Jul 13, 2016

Fix: #1203

rvanvelzen pushed a commit to rvanvelzen/UglifyJS2 that referenced this issue Jul 15, 2016
@rvanvelzen
Copy link
Collaborator

Fixed via eb63fec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants