[Pkg-javascript-commits] [uglifyjs] 96/190: Tighten up @const regex.

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 1b703349cf824020c4dc64a58aa6d0dc3b809cea
Author: Samuel Reed <samuel.trace.reed at gmail.com>
Date:   Wed Jan 20 11:35:45 2016 -0600

    Tighten up @const regex.
---
 lib/scope.js               |  2 +-
 test/compress/dead-code.js | 26 +++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/lib/scope.js b/lib/scope.js
index 794254d..4cea517 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -364,7 +364,7 @@ AST_Symbol.DEFMETHOD("global", function(){
 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);
+    return lastComment && /@const\b/.test(lastComment.value);
 });
 
 AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js
index 8aad336..fa4b37d 100644
--- a/test/compress/dead-code.js
+++ b/test/compress/dead-code.js
@@ -138,6 +138,29 @@ dead_code_const_annotation: {
     }
 }
 
+dead_code_const_annotation_regex: {
+    options = {
+        dead_code    : true,
+        loops        : true,
+        booleans     : true,
+        conditionals : true,
+        evaluate     : true
+    };
+    input: {
+        var unused;
+        // @constraint this shouldn't be a constant
+        var CONST_FOO_ANN = false;
+        if (CONST_FOO_ANN) {
+            console.log("reachable");
+        }
+    }
+    expect: {
+        var unused;
+        var CONST_FOO_ANN = !1;
+        CONST_FOO_ANN && console.log('reachable');
+    }
+}
+
 dead_code_const_annotation_complex_scope: {
     options = {
         dead_code    : true,
@@ -149,7 +172,8 @@ dead_code_const_annotation_complex_scope: {
     input: {
         var unused_var;
         /** @const */ var test = 'test';
-        /** @const */ var CONST_FOO_ANN = false;
+        // @const
+        var CONST_FOO_ANN = false;
         var unused_var_2;
         if (CONST_FOO_ANN) {
             console.log("unreachable");

-- 
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