Tighten up @const regex.

This commit is contained in:
Samuel Reed
2016-01-20 11:35:45 -06:00
parent 4a7179ff91
commit 1b703349cf
2 changed files with 26 additions and 2 deletions

View File

@@ -364,7 +364,7 @@ AST_Symbol.DEFMETHOD("global", function(){
AST_Var.DEFMETHOD("has_const_pragma", function() { AST_Var.DEFMETHOD("has_const_pragma", function() {
var comments_before = this.start && this.start.comments_before; var comments_before = this.start && this.start.comments_before;
var lastComment = comments_before && comments_before[comments_before.length - 1]; 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){ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){

View File

@@ -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: { dead_code_const_annotation_complex_scope: {
options = { options = {
dead_code : true, dead_code : true,
@@ -149,7 +172,8 @@ dead_code_const_annotation_complex_scope: {
input: { input: {
var unused_var; var unused_var;
/** @const */ var test = 'test'; /** @const */ var test = 'test';
/** @const */ var CONST_FOO_ANN = false; // @const
var CONST_FOO_ANN = false;
var unused_var_2; var unused_var_2;
if (CONST_FOO_ANN) { if (CONST_FOO_ANN) {
console.log("unreachable"); console.log("unreachable");