[Pkg-javascript-commits] [uglifyjs] 95/190: Simplify by skipping extra tree walk.

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:16 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit 4a7179ff9183cd27d036043c0bbcb01d1604d824
Author: Samuel Reed <samuel.trace.reed at gmail.com>
Date:   Wed Jan 20 11:03:41 2016 -0600

    Simplify by skipping extra tree walk.
---
 lib/scope.js | 38 ++++++++++----------------------------
 1 file changed, 10 insertions(+), 28 deletions(-)

diff --git a/lib/scope.js b/lib/scope.js
index 144ae48..794254d 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -94,6 +94,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
     var scope = self.parent_scope = null;
     var labels = new Dictionary();
     var defun = null;
+    var last_var_had_const_pragma = false;
     var nesting = 0;
     var tw = new TreeWalker(function(node, descend){
         if (options.screw_ie8 && node instanceof AST_Catch) {
@@ -151,10 +152,13 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
             // later.
             (node.scope = defun.parent_scope).def_function(node);
         }
+        else if (node instanceof AST_Var) {
+            last_var_had_const_pragma = node.has_const_pragma();
+        }
         else if (node instanceof AST_SymbolVar
                  || node instanceof AST_SymbolConst) {
             var def = defun.def_variable(node);
-            def.constant = node instanceof AST_SymbolConst || node.has_const_pragma();
+            def.constant = node instanceof AST_SymbolConst || last_var_had_const_pragma;
             def.init = tw.parent().value;
         }
         else if (node instanceof AST_SymbolCatch) {
@@ -357,33 +361,11 @@ AST_Symbol.DEFMETHOD("global", function(){
     return this.definition().global;
 });
 
-AST_Symbol.DEFMETHOD("has_const_pragma", function() {
-    var symbol = this;
-    var symbol_has_pragma = false;
-    var pragma_found = false;
-    var found_symbol = false;
-    // Walk the current scope, looking for a comment with the @const pragma.
-    // If it exists, mark a bool that will remain true only for the next iteration.
-    // If the next iteration is this symbol, then we return true.
-    // Otherwise we stop descending and get out of here.
-    var tw = new TreeWalker(function(node, descend){
-        // This is our symbol. Was the pragma before this?
-        if (node.name === symbol) {
-            found_symbol = true;
-            symbol_has_pragma = pragma_found;
-        }
-
-        // Look for the /** @const */ pragma
-        var comments_before = node.start && node.start.comments_before;
-        var lastComment = comments_before && comments_before[comments_before.length - 1];
-        pragma_found = lastComment && /@const/.test(lastComment.value);
-
-        // no need to descend after finding our node
-        return found_symbol;
-    });
-    this.scope.walk(tw);
-    return symbol_has_pragma;
-})
+AST_Var.DEFMETHOD("has_const_pragma", function() {
+    var comments_before = this.start && this.start.comments_before;
+    var lastComment = comments_before && comments_before[comments_before.length - 1];
+    return lastComment && /@const/.test(lastComment.value);
+});
 
 AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){
     return defaults(options, {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list