aboutsummaryrefslogtreecommitdiff
path: root/test/compress/templates.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-01 09:20:13 +0000
committerGitHub <noreply@github.com>2021-02-01 17:20:13 +0800
commitba6e29d6fd8df2434cb372b94c7aaccb68bc272f (patch)
tree90502d564901f98168ce35538cdacbb1b11c5da0 /test/compress/templates.js
parentd4685640a00a0c998041c96ec197e613bd67b7b3 (diff)
downloadtracifyjs-ba6e29d6fd8df2434cb372b94c7aaccb68bc272f.tar.gz
tracifyjs-ba6e29d6fd8df2434cb372b94c7aaccb68bc272f.zip
introduce `templates` (#4603)
Diffstat (limited to 'test/compress/templates.js')
-rw-r--r--test/compress/templates.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/test/compress/templates.js b/test/compress/templates.js
index 07aff0c5..ef2a534b 100644
--- a/test/compress/templates.js
+++ b/test/compress/templates.js
@@ -53,6 +53,26 @@ tagged_chain: {
node_version: ">=4"
}
+tag_parenthesis_arrow: {
+ input: {
+ console.log((s => s.raw[0])`\tPASS`.slice(2));
+ }
+ expect_exact: "console.log((s=>s.raw[0])`\\tPASS`.slice(2));"
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}
+
+tag_parenthesis_new: {
+ input: {
+ (new function() {
+ return console.log;
+ })`foo`;
+ }
+ expect_exact: "(new function(){return console.log})`foo`;"
+ expect_stdout: true
+ node_version: ">=4"
+}
+
malformed_escape: {
input: {
(function(s) {
@@ -68,6 +88,7 @@ malformed_escape: {
evaluate: {
options = {
evaluate: true,
+ templates: false,
}
input: {
console.log(`foo ${ function(a, b) {
@@ -80,3 +101,100 @@ evaluate: {
expect_stdout: "foo 42"
node_version: ">=4"
}
+
+evaluate_templates: {
+ options = {
+ evaluate: true,
+ templates: true,
+ }
+ input: {
+ console.log(`foo ${ function(a, b) {
+ return a * b;
+ }(6, 7) }`);
+ }
+ expect: {
+ console.log("foo 42");
+ }
+ expect_stdout: "foo 42"
+ node_version: ">=4"
+}
+
+partial_evaluate: {
+ options = {
+ evaluate: true,
+ templates: true,
+ }
+ input: {
+ console.log(`${6 * 7} foo ${console ? `PA` + "SS" : `FA` + `IL`}`);
+ }
+ expect: {
+ console.log(`42 foo ${console ? "PASS" : "FAIL"}`);
+ }
+ expect_stdout: "42 foo PASS"
+ node_version: ">=4"
+}
+
+malformed_evaluate: {
+ options = {
+ evaluate: true,
+ templates: true,
+ }
+ input: {
+ console.log(`\67 ${6 * 7}`);
+ }
+ expect: {
+ console.log(`\67 42`);
+ }
+ expect_stdout: true
+ node_version: ">=4"
+}
+
+unsafe_evaluate: {
+ options = {
+ evaluate: true,
+ templates: true,
+ unsafe: true,
+ }
+ input: {
+ console.log(String.raw`\uFo`);
+ }
+ expect: {
+ console.log("\\uFo");
+ }
+ expect_stdout: "\\uFo"
+ node_version: ">=8"
+}
+
+side_effects: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ `42`;
+ `${console.log("foo")}`;
+ console.log`\nbar`;
+ }
+ expect: {
+ console.log("foo");
+ console.log`\nbar`;
+ }
+ expect_stdout: true
+ node_version: ">=4"
+}
+
+unsafe_side_effects: {
+ options = {
+ side_effects: true,
+ unsafe: true,
+ }
+ input: {
+ `42`;
+ `${console.log("foo")}`;
+ String.raw`\nbar`;
+ }
+ expect: {
+ console.log("foo");
+ }
+ expect_stdout: "foo"
+ node_version: ">=4"
+}