@@ -10663,7 +10663,8 @@ merge(Compressor.prototype, {
|
|||||||
&& self.left.operator == "+"
|
&& self.left.operator == "+"
|
||||||
&& self.left.left instanceof AST_String
|
&& self.left.left instanceof AST_String
|
||||||
&& self.left.left.value == ""
|
&& self.left.left.value == ""
|
||||||
&& self.right.is_string(compressor)) {
|
&& self.right.is_string(compressor)
|
||||||
|
&& (self.left.right.is_constant() || !self.right.has_side_effects(compressor))) {
|
||||||
self.left = self.left.right;
|
self.left = self.left.right;
|
||||||
return self.optimize(compressor);
|
return self.optimize(compressor);
|
||||||
}
|
}
|
||||||
@@ -11392,15 +11393,29 @@ merge(Compressor.prototype, {
|
|||||||
}).transform(compressor),
|
}).transform(compressor),
|
||||||
right: exprs[exprs.length - 1],
|
right: exprs[exprs.length - 1],
|
||||||
}).optimize(compressor);
|
}).optimize(compressor);
|
||||||
if (strs[0] == "") return make_node(AST_Binary, self, {
|
if (strs[0] == "") {
|
||||||
|
var left = make_node(AST_Binary, self, {
|
||||||
operator: "+",
|
operator: "+",
|
||||||
left: exprs[0],
|
left: make_node(AST_String, self, { value: "" }),
|
||||||
|
right: exprs[0],
|
||||||
|
});
|
||||||
|
for (var i = 1; strs[i] == "" && i < exprs.length; i++) {
|
||||||
|
left = make_node(AST_Binary, self, {
|
||||||
|
operator: "+",
|
||||||
|
left: left,
|
||||||
|
right: exprs[i],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return best_of(compressor, self, make_node(AST_Binary, self, {
|
||||||
|
operator: "+",
|
||||||
|
left: left.transform(compressor),
|
||||||
right: make_node(AST_Template, self, {
|
right: make_node(AST_Template, self, {
|
||||||
expressions: exprs.slice(1),
|
expressions: exprs.slice(i),
|
||||||
strings: strs.slice(1),
|
strings: strs.slice(i),
|
||||||
tag: tag,
|
tag: tag,
|
||||||
}).transform(compressor),
|
}).transform(compressor),
|
||||||
}).optimize(compressor);
|
}).optimize(compressor));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.expressions = exprs;
|
self.expressions = exprs;
|
||||||
self.strings = strs;
|
self.strings = strs;
|
||||||
|
|||||||
@@ -289,3 +289,18 @@ issue_3689: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "00"
|
expect_stdout: "00"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5145: {
|
||||||
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = [];
|
||||||
|
console.log("" + a + ((a[0] = 4) + "2"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = [];
|
||||||
|
console.log("" + a + (a[0] = 4) + "2");
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|||||||
@@ -699,3 +699,47 @@ issue_5136: {
|
|||||||
expect_stdout: "42"
|
expect_stdout: "42"
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5145_1: {
|
||||||
|
options = {
|
||||||
|
strings: true,
|
||||||
|
templates: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = [];
|
||||||
|
console.log(`${a}${a[0] = 42}
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = [];
|
||||||
|
console.log(`${a}${a[0] = 42}
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"42",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5145_2: {
|
||||||
|
options = {
|
||||||
|
strings: true,
|
||||||
|
templates: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = [];
|
||||||
|
console.log(`${a}${a}${a[0] = 42}
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = [];
|
||||||
|
console.log("" + a + a + (a[0] = 42) + `
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"42",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user