aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-23 21:57:11 +0000
committerGitHub <noreply@github.com>2021-02-24 05:57:11 +0800
commitc88566034756eb17c4ff563901b3a1c95b63f788 (patch)
tree24e376db8595b8152b2685708ee08b7f9e194758 /test
parentd68d155f93a355a9f6f0451150186b7fad8c58b8 (diff)
downloadtracifyjs-c88566034756eb17c4ff563901b3a1c95b63f788.tar.gz
tracifyjs-c88566034756eb17c4ff563901b3a1c95b63f788.zip
support nullish coalescing operator (#4678)
Diffstat (limited to 'test')
-rw-r--r--test/compress/arrows.js18
-rw-r--r--test/compress/classes.js2
-rw-r--r--test/compress/exports.js4
-rw-r--r--test/compress/functions.js2
-rw-r--r--test/compress/loops.js4
-rw-r--r--test/compress/new.js4
-rw-r--r--test/compress/nullish.js111
-rw-r--r--test/compress/numbers.js2
-rw-r--r--test/compress/templates.js4
-rw-r--r--test/mocha/comments.js2
-rw-r--r--test/mocha/parentheses.js2
-rw-r--r--test/ufuzz/index.js2
12 files changed, 135 insertions, 22 deletions
diff --git a/test/compress/arrows.js b/test/compress/arrows.js
index e7322b72..096503d6 100644
--- a/test/compress/arrows.js
+++ b/test/compress/arrows.js
@@ -34,7 +34,7 @@ destructured_funarg: {
node_version: ">=6"
}
-await_parenthesis: {
+await_parentheses: {
input: {
async function f() {
await (a => a);
@@ -43,7 +43,7 @@ await_parenthesis: {
expect_exact: "async function f(){await(a=>a)}"
}
-for_parenthesis_init: {
+for_parentheses_init: {
input: {
for (a => (a in a); console.log(42););
}
@@ -52,7 +52,7 @@ for_parenthesis_init: {
node_version: ">=4"
}
-for_parenthesis_condition: {
+for_parentheses_condition: {
input: {
for (console.log(42); a => (a in a);)
break;
@@ -62,7 +62,7 @@ for_parenthesis_condition: {
node_version: ">=4"
}
-for_parenthesis_step: {
+for_parentheses_step: {
input: {
for (; console.log(42); a => (a in a));
}
@@ -71,7 +71,7 @@ for_parenthesis_step: {
node_version: ">=4"
}
-for_assign_parenthesis_init: {
+for_assign_parentheses_init: {
input: {
for (f = a => (a in a); console.log(42););
}
@@ -80,7 +80,7 @@ for_assign_parenthesis_init: {
node_version: ">=4"
}
-for_assign_parenthesis_condition: {
+for_assign_parentheses_condition: {
input: {
for (console.log(42); f = a => (a in a);)
break;
@@ -90,7 +90,7 @@ for_assign_parenthesis_condition: {
node_version: ">=4"
}
-for_assign_parenthesis_step: {
+for_assign_parentheses_step: {
input: {
for (; console.log(42); f = a => (a in a));
}
@@ -99,7 +99,7 @@ for_assign_parenthesis_step: {
node_version: ">=4"
}
-for_declaration_parenthesis_init: {
+for_declaration_parentheses_init: {
input: {
for (var f = a => (a in a); console.log(42););
}
@@ -108,7 +108,7 @@ for_declaration_parenthesis_init: {
node_version: ">=4"
}
-for_statement_parenthesis_init: {
+for_statement_parentheses_init: {
input: {
for (a => {
a in a;
diff --git a/test/compress/classes.js b/test/compress/classes.js
index 8c5575c0..390ae525 100644
--- a/test/compress/classes.js
+++ b/test/compress/classes.js
@@ -158,7 +158,7 @@ yield: {
node_version: ">=12"
}
-conditional_parenthesis: {
+conditional_parentheses: {
options = {
conditionals: true,
}
diff --git a/test/compress/exports.js b/test/compress/exports.js
index d3a4ffce..e0690503 100644
--- a/test/compress/exports.js
+++ b/test/compress/exports.js
@@ -38,7 +38,7 @@ defaults: {
expect_exact: "export default 42;export default async;export default(x,y)=>x*x;export default class{}export default function*(a,b){}export default async function f({c:c},...[d]){}"
}
-defaults_parenthesis_1: {
+defaults_parentheses_1: {
input: {
export default function() {
console.log("FAIL");
@@ -47,7 +47,7 @@ defaults_parenthesis_1: {
expect_exact: 'export default function(){console.log("FAIL")}console.log("PASS");'
}
-defaults_parenthesis_2: {
+defaults_parentheses_2: {
input: {
export default (async function() {
console.log("PASS");
diff --git a/test/compress/functions.js b/test/compress/functions.js
index f521433d..fe9307ca 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -2053,7 +2053,7 @@ issue_2898: {
expect_stdout: "2"
}
-deduplicate_parenthesis: {
+deduplicate_parentheses: {
input: {
({}).a = b;
(({}).a = b)();
diff --git a/test/compress/loops.js b/test/compress/loops.js
index 0afffae5..b1128f1a 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -501,14 +501,14 @@ do_switch: {
}
}
-in_parenthesis_1: {
+in_parentheses_1: {
input: {
for (("foo" in {});0;);
}
expect_exact: 'for(("foo"in{});0;);'
}
-in_parenthesis_2: {
+in_parentheses_2: {
input: {
for ((function(){ "foo" in {}; });0;);
}
diff --git a/test/compress/new.js b/test/compress/new.js
index a823bb9c..9c99f016 100644
--- a/test/compress/new.js
+++ b/test/compress/new.js
@@ -85,7 +85,7 @@ new_with_unary_prefix: {
expect_exact: 'var bar=(+new Date).toString(32);';
}
-dot_parenthesis_1: {
+dot_parentheses_1: {
input: {
console.log(new (Math.random().constructor) instanceof Number);
}
@@ -93,7 +93,7 @@ dot_parenthesis_1: {
expect_stdout: "true"
}
-dot_parenthesis_2: {
+dot_parentheses_2: {
input: {
console.log(typeof new function(){Math.random()}.constructor);
}
diff --git a/test/compress/nullish.js b/test/compress/nullish.js
new file mode 100644
index 00000000..e8f5ad6c
--- /dev/null
+++ b/test/compress/nullish.js
@@ -0,0 +1,111 @@
+parentheses: {
+ input: {
+ (console.log("foo") || console.log("bar") ?? console.log("baz")) && console.log("moo");
+ }
+ expect_exact:'((console.log("foo")||console.log("bar"))??console.log("baz"))&&console.log("moo");'
+ expect_stdout: [
+ "foo",
+ "bar",
+ "baz",
+ ]
+ node_version: ">=14"
+}
+
+evaluate: {
+ options = {
+ evaluate: true,
+ side_effects: true,
+ }
+ input: {
+ void console.log("foo" ?? "bar") ?? console.log("baz");
+ }
+ expect: {
+ console.log("foo"),
+ console.log("baz");
+ }
+ expect_stdout: [
+ "foo",
+ "baz",
+ ]
+ node_version: ">=14"
+}
+
+conditional_assignment_1: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ console.log(function(a, b) {
+ b ?? (a = "FAIL");
+ return a;
+ }("PASS", !console));
+ }
+ expect: {
+ console.log(function(a, b) {
+ b ?? (a = "FAIL");
+ return a;
+ }("PASS", !console));
+ }
+ expect_stdout: "PASS"
+ node_version: ">=14"
+}
+
+conditional_assignment_2: {
+ options = {
+ conditionals: true,
+ }
+ input: {
+ var a, b = false;
+ a = "PASS",
+ b ?? (a = "FAIL"),
+ console.log(a);
+ }
+ expect: {
+ var a, b = false;
+ a = "PASS",
+ b ?? (a = "FAIL"),
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=14"
+}
+
+conditional_assignment_3: {
+ options = {
+ conditionals: true,
+ join_vars: true,
+ }
+ input: {
+ var a, b = false;
+ a = "PASS",
+ b ?? (a = "FAIL"),
+ console.log(a);
+ }
+ expect: {
+ var a, b = false, a = "PASS";
+ b ?? (a = "FAIL"),
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=14"
+}
+
+conditional_assignment_4: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ console.log(function(a) {
+ !console ?? (a = "FAIL");
+ return a;
+ }("PASS"));
+ }
+ expect: {
+ console.log(function(a) {
+ !console ?? (a = "FAIL");
+ return a;
+ }("PASS"));
+ }
+ expect_stdout: "PASS"
+ node_version: ">=14"
+}
diff --git a/test/compress/numbers.js b/test/compress/numbers.js
index 994cd5cf..d7c0360c 100644
--- a/test/compress/numbers.js
+++ b/test/compress/numbers.js
@@ -777,7 +777,7 @@ issue_1710: {
expect_stdout: true
}
-unary_binary_parenthesis: {
+unary_binary_parentheses: {
options = {
evaluate: true,
}
diff --git a/test/compress/templates.js b/test/compress/templates.js
index d9e95975..b75dc7d7 100644
--- a/test/compress/templates.js
+++ b/test/compress/templates.js
@@ -53,7 +53,7 @@ tagged_chain: {
node_version: ">=4"
}
-tag_parenthesis_arrow: {
+tag_parentheses_arrow: {
input: {
console.log((s => s.raw[0])`\tPASS`.slice(2));
}
@@ -62,7 +62,7 @@ tag_parenthesis_arrow: {
node_version: ">=4"
}
-tag_parenthesis_new: {
+tag_parentheses_new: {
input: {
(new function() {
return console.log;
diff --git a/test/mocha/comments.js b/test/mocha/comments.js
index 9a4b3be6..88cf08c4 100644
--- a/test/mocha/comments.js
+++ b/test/mocha/comments.js
@@ -259,7 +259,7 @@ describe("comments", function() {
assert.strictEqual(result.code, code);
});
- it("Should handle comments around parenthesis correctly", function() {
+ it("Should handle comments around parentheses correctly", function() {
var code = [
"a();",
"/* foo */",
diff --git a/test/mocha/parentheses.js b/test/mocha/parentheses.js
index 373db2da..0fbb4c95 100644
--- a/test/mocha/parentheses.js
+++ b/test/mocha/parentheses.js
@@ -84,7 +84,7 @@ describe("parentheses", function() {
}
});
- it("Should compress leading parenthesis with reasonable performance", function() {
+ it("Should compress leading parentheses with reasonable performance", function() {
this.timeout(30000);
var code = [
"({}?0:1)&&x();",
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index 0625a267..3d0824b6 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -149,6 +149,7 @@ var SUPPORT = function(matrix) {
for_of: "for (var a of []);",
generator: "function* f(){}",
let: "let a;",
+ nullish: "0 ?? 0",
rest: "var [...a] = [];",
rest_object: "var {...a} = {};",
spread: "[...[]];",
@@ -231,6 +232,7 @@ var BINARY_OPS = [
",",
];
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
+if (SUPPORT.nullish) BINARY_OPS.push("??");
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
if (SUPPORT.exponentiation) BINARY_OPS.push("**");