aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-01 15:24:11 +0000
committerGitHub <noreply@github.com>2021-02-01 23:24:11 +0800
commitb27b6807cb01b6068cecda435b6b6b2a2ef5af07 (patch)
tree5c4884d1356c8c027b206110f78cf806eda52a82
parentba6e29d6fd8df2434cb372b94c7aaccb68bc272f (diff)
downloadtracifyjs-b27b6807cb01b6068cecda435b6b6b2a2ef5af07.tar.gz
tracifyjs-b27b6807cb01b6068cecda435b6b6b2a2ef5af07.zip
fix corner case in `collapse_vars` (#4605)
fixes #4604
-rw-r--r--lib/compress.js1
-rw-r--r--test/compress/templates.js24
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f894a6cb..ac7aa3e0 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1942,6 +1942,7 @@ merge(Compressor.prototype, {
var def = node.definition();
return (in_try || def.scope.resolve() !== scope) && !can_drop_symbol(node);
}
+ if (node instanceof AST_Template) return node.tag && !is_raw_tag(compressor, node.tag);
if (node instanceof AST_This) return symbol_in_lvalues(node, parent);
if (node instanceof AST_VarDef) {
if (check_destructured(node.name)) return true;
diff --git a/test/compress/templates.js b/test/compress/templates.js
index ef2a534b..3b0e983c 100644
--- a/test/compress/templates.js
+++ b/test/compress/templates.js
@@ -198,3 +198,27 @@ unsafe_side_effects: {
expect_stdout: "foo"
node_version: ">=4"
}
+
+issue_4604: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var a = 0, log = console.log;
+ a = "FAIL";
+ (function() {
+ a = "PASS";
+ })``;
+ log(a);
+ }
+ expect: {
+ var a = 0, log = console.log;
+ a = "FAIL";
+ (function() {
+ a = "PASS";
+ })``;
+ log(a);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}