aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-10-03 00:03:39 +0100
committerGitHub <noreply@github.com>2020-10-03 07:03:39 +0800
commit8cb509d50e8bbc4c79d9bd0274a625f5ec37fe42 (patch)
tree42afe7f83497c990b2c153cdd325e751260fd95f
parentbaf4903aa7c36bd614d3547403d6794bf77ab472 (diff)
downloadtracifyjs-8cb509d50e8bbc4c79d9bd0274a625f5ec37fe42.tar.gz
tracifyjs-8cb509d50e8bbc4c79d9bd0274a625f5ec37fe42.zip
fix corner case in `merge_vars` (#4170)
fixes #4168
-rw-r--r--lib/compress.js8
-rw-r--r--test/compress/merge_vars.js80
2 files changed, 87 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 27ddd22f..513528e7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4406,7 +4406,12 @@ merge(Compressor.prototype, {
push();
segment.block = node;
if (node === self) root = segment;
- if (node instanceof AST_Lambda && node.name) references[node.name.definition().id] = false;
+ if (node instanceof AST_Lambda) {
+ if (node.name) references[node.name.definition().id] = false;
+ if (node.uses_arguments && !tw.has_directive("use strict")) node.argnames.forEach(function(node) {
+ references[node.definition().id] = false;
+ });
+ }
descend();
pop();
return true;
@@ -4474,6 +4479,7 @@ merge(Compressor.prototype, {
return true;
}
});
+ tw.directives = Object.create(compressor.directives);
self.walk(tw);
var merged = Object.create(null);
while (first.length && last.length) {
diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js
index 5f4b6606..a12781d3 100644
--- a/test/compress/merge_vars.js
+++ b/test/compress/merge_vars.js
@@ -2928,3 +2928,83 @@ issue_4157_2: {
}
expect_stdout: "undefined"
}
+
+issue_4168: {
+ options = {
+ merge_vars: true,
+ }
+ input: {
+ var o = {
+ f: function(a, b, c) {
+ var d = a.d;
+ var e = b.e;
+ var f = c.f;
+ this.g(arguments);
+ if (d)
+ console.log(e, f);
+ },
+ g: function(args) {
+ console.log(args[0], args[1], args[2]);
+ },
+ };
+ o.f("PASS", true, 42);
+ }
+ expect: {
+ var o = {
+ f: function(a, b, c) {
+ var d = a.d;
+ var e = b.e;
+ var f = c.f;
+ this.g(arguments);
+ if (d)
+ console.log(e, f);
+ },
+ g: function(args) {
+ console.log(args[0], args[1], args[2]);
+ },
+ };
+ o.f("PASS", true, 42);
+ }
+ expect_stdout: "PASS true 42"
+}
+
+issue_4168_use_strict: {
+ options = {
+ merge_vars: true,
+ }
+ input: {
+ "use strict";
+ var o = {
+ f: function(a, b, c) {
+ var d = a.d;
+ var e = b.e;
+ var f = c.f;
+ this.g(arguments);
+ if (d)
+ console.log(e, f);
+ },
+ g: function(args) {
+ console.log(args[0], args[1], args[2]);
+ },
+ };
+ o.f("PASS", true, 42);
+ }
+ expect: {
+ "use strict";
+ var o = {
+ f: function(d, e, f) {
+ var d = d.d;
+ var e = e.e;
+ var f = f.f;
+ this.g(arguments);
+ if (d)
+ console.log(e, f);
+ },
+ g: function(args) {
+ console.log(args[0], args[1], args[2]);
+ },
+ };
+ o.f("PASS", true, 42);
+ }
+ expect_stdout: "PASS true 42"
+}