diff options
author | Samuel Reed <samuel.trace.reed@gmail.com> | 2016-01-20 11:35:45 -0600 |
---|---|---|
committer | Samuel Reed <samuel.trace.reed@gmail.com> | 2016-01-20 11:35:45 -0600 |
commit | 1b703349cf824020c4dc64a58aa6d0dc3b809cea (patch) | |
tree | 58fbf0bf3c3e3caca18245cbbd6e8b9528b8da92 | |
parent | 4a7179ff9183cd27d036043c0bbcb01d1604d824 (diff) | |
download | tracifyjs-1b703349cf824020c4dc64a58aa6d0dc3b809cea.tar.gz tracifyjs-1b703349cf824020c4dc64a58aa6d0dc3b809cea.zip |
Tighten up @const regex.
-rw-r--r-- | lib/scope.js | 2 | ||||
-rw-r--r-- | test/compress/dead-code.js | 26 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/scope.js b/lib/scope.js index 794254d4..4cea5176 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 8aad336c..fa4b37d6 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");
|