aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-09-16 15:18:28 +0100
committerGitHub <noreply@github.com>2020-09-16 22:18:28 +0800
commit219aac6a84d357b1bd8fa5eb3ba754bf6cfa6498 (patch)
treeb9579e81b492380aebf74d63b458aa50395c8bb0
parent20391850518f4050917a4812af07520eb47cfecf (diff)
downloadtracifyjs-219aac6a84d357b1bd8fa5eb3ba754bf6cfa6498.tar.gz
tracifyjs-219aac6a84d357b1bd8fa5eb3ba754bf6cfa6498.zip
fix corner case in `merge_vars` (#4113)
fixes #4112
-rw-r--r--lib/compress.js9
-rw-r--r--test/compress/merge_vars.js36
2 files changed, 42 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index dbf4e09d..a79b909d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4468,20 +4468,23 @@ merge(Compressor.prototype, {
skipped.unshift(tail);
continue;
}
+ var orig = [], refs = [];
if (id in declarations) declarations[id].forEach(function(sym) {
sym.thedef = def;
sym.name = def.name;
- def.orig.push(sym);
+ orig.push(sym);
});
references[id].forEach(function(sym) {
sym.thedef = def;
sym.name = def.name;
if (sym instanceof AST_SymbolRef) {
- def.references.push(sym);
+ refs.push(sym);
} else {
- def.orig.push(sym);
+ orig.push(sym);
}
});
+ def.orig = orig.concat(def.orig);
+ def.references = refs.concat(def.references);
def.fixed = tail.definition.fixed && def.fixed;
merged[id] = def;
break;
diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js
index f83643e3..fd650f9d 100644
--- a/test/compress/merge_vars.js
+++ b/test/compress/merge_vars.js
@@ -450,3 +450,39 @@ issue_4111: {
}
expect_stdout: "2"
}
+
+issue_4112: {
+ options = {
+ functions: true,
+ merge_vars: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ console.log(typeof function() {
+ try {
+ throw 42;
+ } catch (e) {
+ var o = e;
+ for (e in o);
+ var a = function() {};
+ console.log;
+ return a;
+ }
+ }());
+ }
+ expect: {
+ console.log(typeof function() {
+ try {
+ throw 42;
+ } catch (e) {
+ var a = e;
+ for (e in a);
+ a = function() {};
+ console.log;
+ return a;
+ }
+ }());
+ }
+ expect_stdout: "function"
+}