Permalink
Browse files

mangled name of a function expression should not clash with a name in…

… the

parent scope, in order to deal with a 15 years-old IE bug. (fixes #161)

thanks everyone for the discussion and patience!
  • Loading branch information...
1 parent 068454a commit ae88177fde6a7e54b047ee0d387ee539126016c2 @mishoo committed Jun 26, 2011
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/process.js
View
@@ -339,16 +339,17 @@ Scope.prototype = {
return m;
}
},
+ set_mangle: function(name, m) {
+ this.rev_mangled[m] = name;
+ return this.mangled[name] = m;
+ },
get_mangled: function(name, newMangle) {
if (this.uses_eval || this.uses_with) return name; // no mangle if eval or with is in use
var s = this.has(name);
if (!s) return name; // not in visible scope, no mangle
if (HOP(s.mangled, name)) return s.mangled[name]; // already mangled in this scope
if (!newMangle) return name; // not found and no mangling requested
-
- var m = s.next_mangled();
- s.rev_mangled[m] = name;
- return s.mangled[name] = m;
+ return s.set_mangle(name, s.next_mangled());
},
define: function(name) {
if (name != null)
@@ -484,7 +485,9 @@ function ast_mangle(ast, options) {
var is_defun = this[0] == "defun";
if (is_defun && name) name = get_mangled(name);
body = with_scope(body.scope, function(){
- if (!is_defun && name) name = get_mangled(name);
+ if (!is_defun && name) {
+ name = scope.set_mangle(name, scope.parent.next_mangled());
+ }
args = MAP(args, function(name){ return get_mangled(name) });
return MAP(body, walk);
});

0 comments on commit ae88177

Please sign in to comment.