aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-17 19:10:16 +0000
committerGitHub <noreply@github.com>2020-12-18 03:10:16 +0800
commitab82be82b28c8fed0643569700d9b5ff2f093aea (patch)
treeb308e582f626519502f3b87fb2d7ab123c466620
parent02fdcfde01cf41cae9449dbde4ceb74564bb35f3 (diff)
downloadtracifyjs-ab82be82b28c8fed0643569700d9b5ff2f093aea.tar.gz
tracifyjs-ab82be82b28c8fed0643569700d9b5ff2f093aea.zip
fix corner case in `collapse_vars` (#4391)
fixes #4390
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/arrows.js29
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 2c50cb37..8fe0ad62 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1776,7 +1776,9 @@ merge(Compressor.prototype, {
can_replace = false;
var after = stop_after;
var if_hit = stop_if_hit;
- for (var i = 0; !abort && i < fn.body.length; i++) {
+ if (fn instanceof AST_Arrow && fn.value) {
+ fn.value.transform(scanner);
+ } else for (var i = 0; !abort && i < fn.body.length; i++) {
var stat = fn.body[i];
if (stat instanceof AST_Return) {
if (stat.value) stat.value.transform(scanner);
diff --git a/test/compress/arrows.js b/test/compress/arrows.js
index eded9134..34af3505 100644
--- a/test/compress/arrows.js
+++ b/test/compress/arrows.js
@@ -351,3 +351,32 @@ issue_4388: {
expect_stdout: "undefined"
node_version: ">=4"
}
+
+issue_4390: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ function log() {
+ console.log.apply(console, arguments);
+ }
+ var a = 42, b = "FAIL";
+ b = "PASS";
+ (c => log(b, c))(a);
+ log(b);
+ }
+ expect: {
+ function log() {
+ console.log.apply(console, arguments);
+ }
+ var a = 42, b = "FAIL";
+ b = "PASS";
+ (c => log(b, c))(a);
+ log(b);
+ }
+ expect_stdout: [
+ "PASS 42",
+ "PASS",
+ ]
+ node_version: ">=4"
+}