@@ -10778,7 +10778,8 @@ 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 tag = self.tag;
|
||||
if (!tag || is_raw_tag(compressor, tag)) {
|
||||
var exprs = self.expressions.slice();
|
||||
var strs = self.strings.slice();
|
||||
var CHANGED = false;
|
||||
@@ -10786,6 +10787,7 @@ merge(Compressor.prototype, {
|
||||
var node = exprs[i];
|
||||
var ev = node.evaluate(compressor);
|
||||
if (ev === node) continue;
|
||||
if (tag && /\r|\\|`/.test(ev)) continue;
|
||||
ev = ("" + ev).replace(/\r|\\|`/g, function(s) {
|
||||
return "\\" + (s == "\r" ? "r" : s);
|
||||
});
|
||||
@@ -10794,11 +10796,11 @@ merge(Compressor.prototype, {
|
||||
if (typeof make_node(AST_Template, self, {
|
||||
expressions: [],
|
||||
strings: [ combined ],
|
||||
tag: self.tag,
|
||||
tag: tag,
|
||||
}).evaluate(compressor) != typeof make_node(AST_Template, self, {
|
||||
expressions: [ node ],
|
||||
strings: strs.slice(i, i + 2),
|
||||
tag: self.tag,
|
||||
tag: tag,
|
||||
}).evaluate(compressor)) continue;
|
||||
exprs.splice(i, 1);
|
||||
strs.splice(i, 2, combined);
|
||||
|
||||
@@ -398,3 +398,24 @@ issue_4676: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_4931: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
templates: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
console.log(String.raw`${typeof A} ${"\r"}`);
|
||||
console.log(String.raw`${"\\"} ${"`"}`);
|
||||
}
|
||||
expect: {
|
||||
console.log(String.raw`${typeof A} ${"\r"}`);
|
||||
console.log("\\ `");
|
||||
}
|
||||
expect_stdout: [
|
||||
"undefined \r",
|
||||
"\\ `",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user