[Pkg-javascript-commits] [uglifyjs] 140/228: fix invalid `AST_For.init` (#1657)
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:24 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit a30092e20f6a1e23706f87ca998121b8832a57bb
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sat Mar 25 03:18:36 2017 +0800
fix invalid `AST_For.init` (#1657)
Turns out the only place in `Compressor` which can generate invalid `AST_For.init` is within `drop_unused()`, so focus the fix-up efforts.
supercedes #1652
fixes #1656
---
lib/compress.js | 4 +++-
test/compress/drop-unused.js | 14 ++++++++++++++
test/compress/issue-1656.js | 45 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/lib/compress.js b/lib/compress.js
index e13985e..ab7cca6 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1961,6 +1961,9 @@ merge(Compressor.prototype, {
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
body: body
});
+ } else if (is_empty(node.init)) {
+ node.init = null;
+ return node;
}
}
if (node instanceof AST_Scope && node !== self)
@@ -2327,7 +2330,6 @@ merge(Compressor.prototype, {
};
OPT(AST_For, function(self, compressor){
- if (is_empty(self.init)) self.init = null;
if (!compressor.option("loops")) return self;
if (self.condition) {
var cond = self.condition.evaluate(compressor);
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 9f3bf77..fabf8d9 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -791,3 +791,17 @@ issue_1583: {
}
}
}
+
+issue_1656: {
+ options = {
+ toplevel: true,
+ unused: true,
+ }
+ beautify = {
+ beautify: true,
+ }
+ input: {
+ for(var a=0;;);
+ }
+ expect_exact: "for (;;) ;"
+}
diff --git a/test/compress/issue-1656.js b/test/compress/issue-1656.js
new file mode 100644
index 0000000..8b683a2
--- /dev/null
+++ b/test/compress/issue-1656.js
@@ -0,0 +1,45 @@
+f7: {
+ options = {
+ booleans: true,
+ cascade: true,
+ collapse_vars: true,
+ comparisons: true,
+ conditionals: true,
+ dead_code: true,
+ drop_debugger: true,
+ evaluate: true,
+ hoist_funs: true,
+ if_return: true,
+ join_vars: true,
+ loops: true,
+ negate_iife: true,
+ passes: 3,
+ properties: true,
+ reduce_vars: true,
+ sequences: true,
+ side_effects: true,
+ toplevel: true,
+ unused: true,
+ }
+ beautify = {
+ beautify: true,
+ }
+ input: {
+ var a = 100, b = 10;
+ function f22464() {
+ var brake146670 = 5;
+ while (((b = a) ? !a : ~a ? null : b += a) && --brake146670 > 0) {
+ }
+ }
+ f22464();
+ console.log(a, b);
+ }
+ expect_exact: [
+ "var a = 100, b = 10;",
+ "",
+ "!function() {",
+ " for (;b = a, !1; ) ;",
+ "}(), console.log(a, b);",
+ ]
+ expect_stdout: true
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list