aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/scope.js2
-rw-r--r--test/compress/dead-code.js26
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");