aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-15 13:54:05 +0000
committerGitHub <noreply@github.com>2021-03-15 21:54:05 +0800
commit176581d732276df1578f1eb98e722ec3b5f52bbd (patch)
treefa2fb71cdfb7135469c3750a548f117ac3164820
parent01aa078e9cae82e16aa1faad092dbd4fbce895e2 (diff)
downloadtracifyjs-176581d732276df1578f1eb98e722ec3b5f52bbd.tar.gz
tracifyjs-176581d732276df1578f1eb98e722ec3b5f52bbd.zip
fix corner cases with template literals (#4780)
-rw-r--r--lib/compress.js2
-rw-r--r--lib/output.js2
-rw-r--r--test/compress/templates.js40
-rw-r--r--test/ufuzz/index.js4
4 files changed, 46 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 0d87e308..3560c13f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1511,6 +1511,8 @@ merge(Compressor.prototype, {
var wrap = false;
if (parent.TYPE == "Call") {
wrap = parent.expression === orig && needs_unbinding(compressor, val);
+ } else if (parent instanceof AST_Template) {
+ wrap = parent.tag === orig && needs_unbinding(compressor, val);
} else if (parent instanceof AST_UnaryPrefix) {
wrap = parent.operator == "delete"
|| parent.operator == "typeof" && is_undeclared_ref(val);
diff --git a/lib/output.js b/lib/output.js
index 00037ce8..e6b49804 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -746,6 +746,8 @@ function OutputStream(options) {
|| p instanceof AST_PropAccess && p.expression === this
// ...(foo, bar, baz)
|| p instanceof AST_Spread
+ // (foo, bar)`baz`
+ || p instanceof AST_Template && p.tag === this
// !(foo, bar, baz)
|| p instanceof AST_Unary
// var a = (1, 2), b = a + a; ---> b == 4
diff --git a/test/compress/templates.js b/test/compress/templates.js
index b75dc7d7..a27c6b8b 100644
--- a/test/compress/templates.js
+++ b/test/compress/templates.js
@@ -73,6 +73,20 @@ tag_parentheses_new: {
node_version: ">=4"
}
+tag_parentheses_sequence: {
+ input: {
+ var o = {
+ f() {
+ console.log(this === o ? "FAIL" : "PASS");
+ },
+ };
+ (42, o.f)``;
+ }
+ expect_exact: 'var o={f(){console.log(this===o?"FAIL":"PASS")}};(42,o.f)``;'
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}
+
malformed_escape: {
input: {
(function(s) {
@@ -211,7 +225,7 @@ unsafe_evaluate: {
node_version: ">=8"
}
-side_effects: {
+side_effects_1: {
options = {
side_effects: true,
}
@@ -228,6 +242,30 @@ side_effects: {
node_version: ">=4"
}
+side_effects_2: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ var o = {
+ f() {
+ console.log(this === o ? "FAIL" : "PASS");
+ },
+ };
+ (42, o.f)``;
+ }
+ expect: {
+ var o = {
+ f() {
+ console.log(this === o ? "FAIL" : "PASS");
+ },
+ };
+ (0, o.f)``;
+ }
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}
+
unsafe_side_effects: {
options = {
side_effects: true,
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index c90eb553..c5a2e75d 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -1493,7 +1493,9 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
case p++:
var name = getVarName();
var fn = name + "." + getDotKey();
- var s = "typeof " + fn + ' == "function" && --_calls_ >= 0 && ' + fn + createArgs(recurmax, stmtDepth, canThrow);
+ var s = "typeof " + fn + ' == "function" && --_calls_ >= 0 && ';
+ s += rng(5) ? fn : "(" + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ", " + fn + ")";
+ s += createArgs(recurmax, stmtDepth, canThrow);
return mayDefer(canThrow && rng(20) == 0 ? s : name + " && " + s);
case p++:
if (SUPPORT.class) {