diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-01 02:36:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-01 10:36:45 +0800 |
commit | d4685640a00a0c998041c96ec197e613bd67b7b3 (patch) | |
tree | 53ed8185a109028e4270993fc1d6962fcc22495b /test/compress/templates.js | |
parent | ac7b5c07d778d3b70bf39c4c0014e9411d780268 (diff) | |
download | tracifyjs-d4685640a00a0c998041c96ec197e613bd67b7b3.tar.gz tracifyjs-d4685640a00a0c998041c96ec197e613bd67b7b3.zip |
support template literals (#4601)
Diffstat (limited to 'test/compress/templates.js')
-rw-r--r-- | test/compress/templates.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/test/compress/templates.js b/test/compress/templates.js new file mode 100644 index 00000000..07aff0c5 --- /dev/null +++ b/test/compress/templates.js @@ -0,0 +1,82 @@ +simple: { + input: { + console.log(`foo + bar\nbaz`); + } + expect_exact: "console.log(`foo\n bar\\nbaz`);" + expect_stdout: [ + "foo", + " bar", + "baz", + ] + node_version: ">=4" +} + +placeholder: { + input: { + console.log(`foo ${ function(a, b) { + return a * b; + }(6, 7) }`); + } + expect_exact: "console.log(`foo ${function(a,b){return a*b}(6,7)}`);" + expect_stdout: "foo 42" + node_version: ">=4" +} + +nested: { + input: { + console.log(`P${`A${"S"}`}S`); + } + expect_exact: 'console.log(`P${`A${"S"}`}S`);' + expect_stdout: "PASS" + node_version: ">=4" +} + +tagged: { + input: { + console.log(String.raw`foo\nbar`); + } + expect_exact: "console.log(String.raw`foo\\nbar`);" + expect_stdout: "foo\\nbar" + node_version: ">=4" +} + +tagged_chain: { + input: { + function f(strings) { + return strings.join("") || f; + } + console.log(f```${42}``pass`.toUpperCase()); + } + expect_exact: 'function f(strings){return strings.join("")||f}console.log(f```${42}``pass`.toUpperCase());' + expect_stdout: "PASS" + node_version: ">=4" +} + +malformed_escape: { + input: { + (function(s) { + s.forEach((c, i) => console.log(i, c, s.raw[i])); + return () => console.log(arguments); + })`\uFo${42}`(); + } + expect_exact: "(function(s){s.forEach((c,i)=>console.log(i,c,s.raw[i]));return()=>console.log(arguments)})`\\uFo${42}`();" + expect_stdout: true + node_version: ">=4" +} + +evaluate: { + options = { + evaluate: 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" +} |