aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-05-03 15:26:20 +0100
committerGitHub <noreply@github.com>2021-05-03 22:26:20 +0800
commit5d9224deb893c383e9a2c2b11c5926db96bd7a1f (patch)
tree1530028ac02ac50e0b0c8b7740f26e3d738a406c
parent45b6d23d3664382e1b0a77f614bc3744e1de4425 (diff)
downloadtracifyjs-5d9224deb893c383e9a2c2b11c5926db96bd7a1f.tar.gz
tracifyjs-5d9224deb893c383e9a2c2b11c5926db96bd7a1f.zip
fix corner cases with template literals (#4903)
fixes #4902
-rw-r--r--lib/output.js4
-rw-r--r--test/compress/templates.js32
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/output.js b/lib/output.js
index 6272264f..308fcf54 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -709,6 +709,8 @@ function OutputStream(options) {
// (x++)[y]
// (typeof x).y
if (p instanceof AST_PropAccess) return p.expression === this;
+ // (~x)`foo`
+ if (p instanceof AST_Template) return p.tag === this;
}
PARENS(AST_Await, needs_parens_unary);
PARENS(AST_Unary, needs_parens_unary);
@@ -782,6 +784,8 @@ function OutputStream(options) {
if (p instanceof AST_Class) return true;
// (foo && bar)["prop"], (foo && bar).prop
if (p instanceof AST_PropAccess) return p.expression === this;
+ // (foo && bar)``
+ if (p instanceof AST_Template) return p.tag === this;
// typeof (foo && bar)
if (p instanceof AST_Unary) return true;
});
diff --git a/test/compress/templates.js b/test/compress/templates.js
index e46f3c06..bac1f061 100644
--- a/test/compress/templates.js
+++ b/test/compress/templates.js
@@ -62,6 +62,23 @@ tag_parentheses_arrow: {
node_version: ">=4"
}
+tag_parentheses_binary: {
+ options = {
+ collapse_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var f = function() {
+ console.log("PASS");
+ } || console
+ f``;
+ }
+ expect_exact: '(function(){console.log("PASS")}||console)``;'
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}
+
tag_parentheses_new: {
input: {
(new function() {
@@ -87,6 +104,21 @@ tag_parentheses_sequence: {
node_version: ">=4"
}
+tag_parentheses_unary: {
+ input: {
+ var a;
+ try {
+ (~a)``;
+ (a++)``;
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_exact: 'var a;try{(~a)``;(a++)``}catch(e){console.log("PASS")}'
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}
+
malformed_escape: {
input: {
(function(s) {