aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/compress/conditionals.js160
-rw-r--r--test/compress/issue-747.js37
-rw-r--r--test/compress/issue-751.js29
-rwxr-xr-xtest/run-tests.js5
4 files changed, 230 insertions, 1 deletions
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index 1b961812..16ef6d66 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -384,3 +384,163 @@ cond_8: {
a = condition ? 1 : 0;
}
}
+
+conditional_and: {
+ options = {
+ conditionals: true,
+ evaluate : true
+ };
+ input: {
+ var a;
+ // compress these
+
+ a = true && condition;
+ a = 1 && console.log("a");
+ a = 2 * 3 && 2 * condition;
+ a = 5 == 5 && condition + 3;
+ a = "string" && 4 - condition;
+ a = 5 + "" && condition / 5;
+ a = -4.5 && 6 << condition;
+ a = 6 && 7;
+
+ a = false && condition;
+ a = NaN && console.log("b");
+ a = 0 && console.log("c");
+ a = undefined && 2 * condition;
+ a = null && condition + 3;
+ a = 2 * 3 - 6 && 4 - condition;
+ a = 10 == 7 && condition / 5;
+ a = !"string" && 6 % condition;
+ a = 0 && 7;
+
+ // don't compress these
+
+ a = condition && true;
+ a = console.log("a") && 2;
+ a = 4 - condition && "string";
+ a = 6 << condition && -4.5;
+
+ a = condition && false;
+ a = console.log("b") && NaN;
+ a = console.log("c") && 0;
+ a = 2 * condition && undefined;
+ a = condition + 3 && null;
+
+ }
+ expect: {
+ var a;
+
+ a = condition;
+ a = console.log("a");
+ a = 2 * condition;
+ a = condition + 3;
+ a = 4 - condition;
+ a = condition / 5;
+ a = 6 << condition;
+ a = 7;
+
+ a = false;
+ a = NaN;
+ a = 0;
+ a = void 0;
+ a = null;
+ a = 0;
+ a = false;
+ a = false;
+ a = 0;
+
+ a = condition && true;
+ a = console.log("a") && 2;
+ a = 4 - condition && "string";
+ a = 6 << condition && -4.5;
+
+ a = condition && false;
+ a = console.log("b") && NaN;
+ a = console.log("c") && 0;
+ a = 2 * condition && void 0;
+ a = condition + 3 && null;
+ }
+}
+
+conditional_or: {
+ options = {
+ conditionals: true,
+ evaluate : true
+ };
+ input: {
+ var a;
+ // compress these
+
+ a = true || condition;
+ a = 1 || console.log("a");
+ a = 2 * 3 || 2 * condition;
+ a = 5 == 5 || condition + 3;
+ a = "string" || 4 - condition;
+ a = 5 + "" || condition / 5;
+ a = -4.5 || 6 << condition;
+ a = 6 || 7;
+
+ a = false || condition;
+ a = 0 || console.log("b");
+ a = NaN || console.log("c");
+ a = undefined || 2 * condition;
+ a = null || condition + 3;
+ a = 2 * 3 - 6 || 4 - condition;
+ a = 10 == 7 || condition / 5;
+ a = !"string" || 6 % condition;
+ a = null || 7;
+
+ a = console.log(undefined && condition || null);
+ a = console.log(undefined || condition && null);
+
+ // don't compress these
+
+ a = condition || true;
+ a = console.log("a") || 2;
+ a = 4 - condition || "string";
+ a = 6 << condition || -4.5;
+
+ a = condition || false;
+ a = console.log("b") || NaN;
+ a = console.log("c") || 0;
+ a = 2 * condition || undefined;
+ a = condition + 3 || null;
+
+ }
+ expect: {
+ var a;
+
+ a = true;
+ a = 1;
+ a = 6;
+ a = true;
+ a = "string";
+ a = "5";
+ a = -4.5;
+ a = 6;
+
+ a = condition;
+ a = console.log("b");
+ a = console.log("c");
+ a = 2 * condition;
+ a = condition + 3;
+ a = 4 - condition;
+ a = condition / 5;
+ a = 6 % condition;
+ a = 7;
+
+ a = console.log(null);
+ a = console.log(condition && null);
+
+ a = condition || true;
+ a = console.log("a") || 2;
+ a = 4 - condition || "string";
+ a = 6 << condition || -4.5;
+
+ a = condition || false;
+ a = console.log("b") || NaN;
+ a = console.log("c") || 0;
+ a = 2 * condition || void 0;
+ a = condition + 3 || null;
+ }
+}
diff --git a/test/compress/issue-747.js b/test/compress/issue-747.js
new file mode 100644
index 00000000..0a4e4502
--- /dev/null
+++ b/test/compress/issue-747.js
@@ -0,0 +1,37 @@
+dont_reuse_prop: {
+ mangle_props = {
+ regex: /asd/
+ };
+
+ input: {
+ var obj = {};
+ obj.a = 123;
+ obj.asd = 256;
+ console.log(obj.a);
+ }
+ expect: {
+ var obj = {};
+ obj.a = 123;
+ obj.b = 256;
+ console.log(obj.a);
+ }
+}
+
+unmangleable_props_should_always_be_reserved: {
+ mangle_props = {
+ regex: /asd/
+ };
+
+ input: {
+ var obj = {};
+ obj.asd = 256;
+ obj.a = 123;
+ console.log(obj.a);
+ }
+ expect: {
+ var obj = {};
+ obj.b = 256;
+ obj.a = 123;
+ console.log(obj.a);
+ }
+} \ No newline at end of file
diff --git a/test/compress/issue-751.js b/test/compress/issue-751.js
new file mode 100644
index 00000000..829b7ca5
--- /dev/null
+++ b/test/compress/issue-751.js
@@ -0,0 +1,29 @@
+negate_booleans_1: {
+ options = {
+ comparisons: true
+ };
+ input: {
+ var a = !a || !b || !c || !d || !e || !f;
+ }
+ expect: {
+ var a = !(a && b && c && d && e && f);
+ }
+}
+
+negate_booleans_2: {
+ options = {
+ comparisons: true
+ };
+ input: {
+ var match = !x && // should not touch this one
+ (!z || c) &&
+ (!k || d) &&
+ the_stuff();
+ }
+ expect: {
+ var match = !x &&
+ (!z || c) &&
+ (!k || d) &&
+ the_stuff();
+ }
+}
diff --git a/test/run-tests.js b/test/run-tests.js
index 215f6af8..fc7476f9 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -31,7 +31,7 @@ function tmpl() {
function log() {
var txt = tmpl.apply(this, arguments);
- sys.puts(txt);
+ console.log("%s", txt);
}
function log_directory(dir) {
@@ -92,6 +92,9 @@ function run_compress_tests() {
}
var input = as_toplevel(test.input);
var input_code = make_code(test.input);
+ if (test.mangle_props) {
+ input = U.mangle_properties(input, test.mangle_props);
+ }
var output = input.transform(cmp);
output.figure_out_scope();
output = make_code(output, false);