diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/scope.js | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/scope.js b/lib/scope.js index 73442a30..6c19c19a 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -67,18 +67,26 @@ SymbolDef.prototype = { || this.orig[0] instanceof AST_SymbolDefun)); }, mangle: function(options) { - if (!this.mangled_name && !this.unmangleable(options)) { + var cache = options.cache && options.cache.props; + if (this.global && cache && cache.has(this.name)) { + this.mangled_name = cache.get(this.name); + } + else if (!this.mangled_name && !this.unmangleable(options)) { var s = this.scope; if (!options.screw_ie8 && this.orig[0] instanceof AST_SymbolLambda) s = s.parent_scope; this.mangled_name = s.next_mangled(options, this); + if (this.global && cache) { + cache.set(this.name, this.mangled_name); + } } } }; AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ options = defaults(options, { - screw_ie8: false + screw_ie8: false, + cache: null }); // pass 1: setup scope chaining and handle definitions @@ -183,6 +191,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ } }); self.walk(tw); + + if (options.cache) { + this.cname = options.cache.cname; + } }); AST_Scope.DEFMETHOD("init_scope_vars", function(nesting){ @@ -344,6 +356,15 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ // the AST_SymbolDeclaration that it points to). var lname = -1; var to_mangle = []; + + if (options.cache) { + this.globals.each(function(symbol){ + if (options.except.indexOf(symbol.name) < 0) { + to_mangle.push(symbol); + } + }); + } + var tw = new TreeWalker(function(node, descend){ if (node instanceof AST_LabeledStatement) { // lname is incremented when we get to the AST_Label @@ -378,6 +399,10 @@ 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; + } }); AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){ |