aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2013-10-29 13:18:09 +0200
committerMihai Bazon <mihai@bazon.net>2013-10-29 13:18:09 +0200
commita14c6b6574b47ba9fe4e238eea1f1286097d3c5d (patch)
tree607adf89e367b69c8cdc3cb54eb9982442078f21 /lib
parentf1b7094a57cc3fbbe37a2c653f255190b9359c0d (diff)
downloadtracifyjs-a14c6b6574b47ba9fe4e238eea1f1286097d3c5d.tar.gz
tracifyjs-a14c6b6574b47ba9fe4e238eea1f1286097d3c5d.zip
Avoid shadowing name of function expression with function argument
Close #179, #326, #327
Diffstat (limited to 'lib')
-rw-r--r--lib/scope.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/scope.js b/lib/scope.js
index 713a2c92..af6aebf5 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -64,9 +64,9 @@ SymbolDef.prototype = {
mangle: function(options) {
if (!this.mangled_name && !this.unmangleable(options)) {
var s = this.scope;
- if (this.orig[0] instanceof AST_SymbolLambda && !options.screw_ie8)
+ if (!options.screw_ie8 && this.orig[0] instanceof AST_SymbolLambda)
s = s.parent_scope;
- this.mangled_name = s.next_mangled(options);
+ this.mangled_name = s.next_mangled(options, this);
}
}
};
@@ -256,6 +256,19 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
}
});
+AST_Function.DEFMETHOD("next_mangled", function(options, def){
+ // #179, #326
+ // in Safary strict mode, something like (function x(x){...}) is a syntax error;
+ // a function expression's argument cannot shadow the function expression's name
+
+ 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))
+ return name;
+ }
+});
+
AST_Scope.DEFMETHOD("references", function(sym){
if (sym instanceof AST_Symbol) sym = sym.definition();
return this.enclosed.indexOf(sym) < 0 ? null : sym;