aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/compress/dead-code.js117
1 files changed, 117 insertions, 0 deletions
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js
index 5009ae1e..fa4b37d6 100644
--- a/test/compress/dead-code.js
+++ b/test/compress/dead-code.js
@@ -87,3 +87,120 @@ dead_code_constant_boolean_should_warn_more: {
var moo;
}
}
+
+dead_code_const_declaration: {
+ options = {
+ dead_code : true,
+ loops : true,
+ booleans : true,
+ conditionals : true,
+ evaluate : true
+ };
+ input: {
+ var unused;
+ const CONST_FOO = false;
+ if (CONST_FOO) {
+ console.log("unreachable");
+ var moo;
+ function bar() {}
+ }
+ }
+ expect: {
+ var unused;
+ const CONST_FOO = !1;
+ var moo;
+ function bar() {}
+ }
+}
+
+dead_code_const_annotation: {
+ options = {
+ dead_code : true,
+ loops : true,
+ booleans : true,
+ conditionals : true,
+ evaluate : true
+ };
+ input: {
+ var unused;
+ /** @const */ var CONST_FOO_ANN = false;
+ if (CONST_FOO_ANN) {
+ console.log("unreachable");
+ var moo;
+ function bar() {}
+ }
+ }
+ expect: {
+ var unused;
+ var CONST_FOO_ANN = !1;
+ var moo;
+ function bar() {}
+ }
+}
+
+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,
+ loops : true,
+ booleans : true,
+ conditionals : true,
+ evaluate : true
+ };
+ input: {
+ var unused_var;
+ /** @const */ var test = 'test';
+ // @const
+ var CONST_FOO_ANN = false;
+ var unused_var_2;
+ if (CONST_FOO_ANN) {
+ console.log("unreachable");
+ var moo;
+ function bar() {}
+ }
+ if (test === 'test') {
+ var beef = 'good';
+ /** @const */ var meat = 'beef';
+ var pork = 'bad';
+ if (meat === 'pork') {
+ console.log('also unreachable');
+ } else if (pork === 'good') {
+ console.log('reached, not const');
+ }
+ }
+ }
+ expect: {
+ var unused_var;
+ var test = 'test';
+ var CONST_FOO_ANN = !1;
+ var unused_var_2;
+ var moo;
+ function bar() {}
+ var beef = 'good';
+ var meat = 'beef';
+ var pork = 'bad';
+ 'good' === pork && console.log('reached, not const');
+ }
+}