aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js10
-rw-r--r--test/compress/templates.js30
2 files changed, 38 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index c6451012..c16639fb 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -10141,8 +10141,9 @@ merge(Compressor.prototype, {
OPT(AST_Template, function(self, compressor) {
if (!compressor.option("templates")) return self;
if (!self.tag || is_raw_tag(compressor, self.tag)) {
- var exprs = self.expressions;
- var strs = self.strings;
+ var exprs = self.expressions.slice();
+ var strs = self.strings.slice();
+ var CHANGED = false;
for (var i = exprs.length; --i >= 0;) {
var node = exprs[i];
var ev = node.evaluate(compressor);
@@ -10163,6 +10164,11 @@ merge(Compressor.prototype, {
}).evaluate(compressor)) continue;
exprs.splice(i, 1);
strs.splice(i, 2, combined);
+ CHANGED = true;
+ }
+ if (CHANGED) {
+ self.expressions = exprs;
+ self.strings = strs;
}
}
return try_evaluate(compressor, self);
diff --git a/test/compress/templates.js b/test/compress/templates.js
index 8ea4d396..d9e95975 100644
--- a/test/compress/templates.js
+++ b/test/compress/templates.js
@@ -298,3 +298,33 @@ issue_4630: {
expect_stdout: "/PASS/"
node_version: ">=4"
}
+
+issue_4676: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ templates: true,
+ toplevel: true,
+ unsafe:true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b = `foo${a = "PASS"}`;
+ for (var c in f && b)
+ b.p;
+ return a;
+ }
+ console.log(f("FAIL"));
+ }
+ expect: {
+ console.log(function f(a) {
+ var b = "fooPASS";
+ for (var c in f, b)
+ b.p;
+ return "PASS";
+ }());
+ }
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}