aboutsummaryrefslogtreecommitdiff
path: root/test/compress/nullish.js
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/compress/nullish.js
parentd68d155f93a355a9f6f0451150186b7fad8c58b8 (diff)
downloadtracifyjs-c88566034756eb17c4ff563901b3a1c95b63f788.tar.gz
tracifyjs-c88566034756eb17c4ff563901b3a1c95b63f788.zip
support nullish coalescing operator (#4678)
Diffstat (limited to 'test/compress/nullish.js')
-rw-r--r--test/compress/nullish.js111
1 files changed, 111 insertions, 0 deletions
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"
+}