aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-02-17 02:37:13 +0800
committerGitHub <noreply@github.com>2018-02-17 02:37:13 +0800
commitd626e9bf19108177aba438ce81649af9f373bac0 (patch)
tree65d3280c994f65803efccab33148175f59140bc6
parenta2a9459684462224a93710631dcc29624d010e21 (diff)
downloadtracifyjs-d626e9bf19108177aba438ce81649af9f373bac0.tar.gz
tracifyjs-d626e9bf19108177aba438ce81649af9f373bac0.zip
improve `inline` efficiency (#2924)
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/functions.js57
-rw-r--r--test/mocha/minify.js2
3 files changed, 28 insertions, 33 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 65895bb7..63830d09 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4487,6 +4487,8 @@ merge(Compressor.prototype, {
})) {
return false;
}
+ } else if (line instanceof AST_EmptyStatement) {
+ continue;
} else if (stat) {
return false;
} else {
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 2c034559..29c438ae 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -292,11 +292,12 @@ issue_2084: {
}
expect: {
var c = 0;
- !function(c) {
- c = 1 + c,
+ !function() {
+ var c;
+ c = 1 + (c = -1),
c = 1 + (c = 0),
0 !== 23..toString() && (c = 1 + c);
- }(-1),
+ }(),
console.log(c);
}
expect_stdout: "0"
@@ -1051,11 +1052,9 @@ issue_2616: {
}
expect: {
var c = "FAIL";
- (function() {
- !function(NaN) {
- (true << NaN) - 0/0 || (c = "PASS");
- }([]);
- })();
+ !function(NaN) {
+ (true << NaN) - 0/0 || (c = "PASS");
+ }([]);
console.log(c);
}
expect_stdout: "PASS"
@@ -1086,13 +1085,11 @@ issue_2620_1: {
}
expect: {
var c = "FAIL";
- (function() {
- (function(a) {
- if (function(a) {
- a && a();
- }(), a) c = "PASS";
- })(1);
- })(),
+ !function(a) {
+ if (function(a) {
+ a && a();
+ }(), a) c = "PASS";
+ }(1),
console.log(c);
}
expect_stdout: "PASS"
@@ -1160,18 +1157,16 @@ issue_2620_3: {
}
expect: {
var c = "FAIL";
- (function() {
- (function(a, NaN) {
- (function() {
- switch (a) {
- case a:
- break;
- case c = "PASS", NaN:
- break;
- }
- })();
- })(NaN);
- })();
+ !function(a, NaN) {
+ (function() {
+ switch (a) {
+ case a:
+ break;
+ case c = "PASS", NaN:
+ break;
+ }
+ })();
+ }(NaN);
console.log(c);
}
expect_stdout: "PASS"
@@ -1341,11 +1336,9 @@ issue_2630_4: {
}
expect: {
var x = 3, a = 1, b = 2;
- (function() {
- (function() {
- while (--x >= 0 && void (b += ++a));
- })();
- })();
+ !function() {
+ while (--x >= 0 && void (b += ++a));
+ }();
console.log(a);
}
expect_stdout: "2"
diff --git a/test/mocha/minify.js b/test/mocha/minify.js
index 65392ee4..1b0052a4 100644
--- a/test/mocha/minify.js
+++ b/test/mocha/minify.js
@@ -226,7 +226,7 @@ describe("minify", function() {
content: "inline"
}
});
- assert.strictEqual(result.code, "var bar=function(){return function(bar){return bar}}();");
+ assert.strictEqual(result.code, "var bar=function(bar){return bar};");
assert.strictEqual(warnings.length, 1);
assert.strictEqual(warnings[0], "inline source map not found");
} finally {