diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-05 05:08:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 05:08:09 +0800 |
commit | afbcebddf63c7ffa5b0df9b3712ee3b560918f1e (patch) | |
tree | 8348f45f70f00abdb764c328899cd849ee870d23 /lib/scope.js | |
parent | 484e484571448595389e4c6fd9559e47c5591f7a (diff) | |
download | tracifyjs-afbcebddf63c7ffa5b0df9b3712ee3b560918f1e.tar.gz tracifyjs-afbcebddf63c7ffa5b0df9b3712ee3b560918f1e.zip |
fix `mangle` name collision across files (#2722)
Diffstat (limited to 'lib/scope.js')
-rw-r--r-- | lib/scope.js | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/scope.js b/lib/scope.js index de92fc94..801c888c 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -242,10 +242,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ } })); } - - if (options.cache) { - this.cname = options.cache.cname; - } }); AST_Toplevel.DEFMETHOD("def_global", function(node){ @@ -329,10 +325,10 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init){ return symbol.thedef = def; }); -AST_Scope.DEFMETHOD("next_mangled", function(options){ - var ext = this.enclosed; +function next_mangled(scope, options) { + var ext = scope.enclosed; out: while (true) { - var m = base54(++this.cname); + var m = base54(++scope.cname); if (!is_identifier(m)) continue; // skip over "do" // https://github.com/mishoo/UglifyJS2/issues/242 -- do not @@ -349,6 +345,18 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){ } return m; } +} + +AST_Scope.DEFMETHOD("next_mangled", function(options){ + return next_mangled(this, options); +}); + +AST_Toplevel.DEFMETHOD("next_mangled", function(options){ + var name; + do { + name = next_mangled(this, options); + } while (member(name, this.mangled_names)); + return name; }); AST_Function.DEFMETHOD("next_mangled", function(options, def){ @@ -362,7 +370,7 @@ AST_Function.DEFMETHOD("next_mangled", function(options, def){ var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null; while (true) { - var name = AST_Lambda.prototype.next_mangled.call(this, options, def); + var name = next_mangled(this, options); if (!tricky_name || tricky_name != name) return name; } @@ -413,8 +421,14 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ var lname = -1; var to_mangle = []; + var mangled_names = this.mangled_names = []; if (options.cache) { this.globals.each(collect); + if (options.cache.props) { + options.cache.props.each(function(mangled_name) { + push_uniq(mangled_names, mangled_name); + }); + } } var tw = new TreeWalker(function(node, descend){ @@ -443,10 +457,6 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ this.walk(tw); to_mangle.forEach(function(def){ def.mangle(options) }); - if (options.cache) { - options.cache.cname = this.cname; - } - function collect(symbol) { if (!member(symbol.name, options.reserved)) { to_mangle.push(symbol); |