aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-02 17:39:30 +0000
committerGitHub <noreply@github.com>2021-02-02 17:39:30 +0000
commita2f27c7640fee2c981b49ee484a37e1721622bb3 (patch)
tree67ce8a676c7590f7857b3475cbaee59cd5ca28eb /lib/compress.js
parent3c556b8689346f8256781455c0e1b2f00975570f (diff)
downloadtracifyjs-a2f27c7640fee2c981b49ee484a37e1721622bb3.tar.gz
tracifyjs-a2f27c7640fee2c981b49ee484a37e1721622bb3.zip
fix corner cases in `templates` (#4610)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 7293f9df..dbd3dd35 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4416,8 +4416,8 @@ merge(Compressor.prototype, {
}
var exprs = eval_all(this.expressions, compressor, ignore_side_effects, cached, depth);
if (!exprs) return this;
- var ret = decode(this.strings[0]);
var malformed = false;
+ var ret = decode(this.strings[0]);
for (var i = 0; i < exprs.length; i++) {
ret += exprs[i] + decode(this.strings[i + 1]);
}
@@ -4426,7 +4426,7 @@ merge(Compressor.prototype, {
return this;
function decode(str) {
- return str.replace(/\\(u[0-9a-fA-F]{4}|u\{[0-9a-fA-F]+\}|x[0-9a-fA-F]{2}|[0-9]+|[\s\S])/g, function(match, seq) {
+ return str.replace(/\\(u\{[^}]*\}?|u[\s\S]{0,4}|x[\s\S]{0,2}|[0-9]+|[\s\S])/g, function(match, seq) {
var s = decode_escape_sequence(seq);
if (typeof s != "string") malformed = true;
return s;
@@ -9952,8 +9952,18 @@ merge(Compressor.prototype, {
return "\\" + (s == "\r" ? "r" : s);
});
if (ev.length > node.print_to_string().length + 3) continue;
+ var combined = strs[i] + ev + strs[i + 1];
+ if (typeof make_node(AST_Template, self, {
+ expressions: [],
+ strings: [ combined ],
+ tag: self.tag,
+ }).evaluate(compressor) != typeof make_node(AST_Template, self, {
+ expressions: [ node ],
+ strings: strs.slice(i, i + 2),
+ tag: self.tag,
+ }).evaluate(compressor)) continue;
exprs.splice(i, 1);
- strs.splice(i, 2, strs[i] + ev + strs[i + 1]);
+ strs.splice(i, 2, combined);
}
}
return try_evaluate(compressor, self);