[Pkg-javascript-commits] [uglifyjs] 20/491: fix `AST_For.init` patch-up in `drop_unused()` (#1839)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:18 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit 45ce3694807ee0daeb7e0f84c12ffbd8ca4f733c
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sun Apr 23 01:51:56 2017 +0800
fix `AST_For.init` patch-up in `drop_unused()` (#1839)
fixes #1838
---
lib/compress.js | 3 +++
test/compress/drop-unused.js | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/lib/compress.js b/lib/compress.js
index 22e012e..5a8f23b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2066,6 +2066,7 @@ merge(Compressor.prototype, {
// certain combination of unused name + side effect leads to:
// https://github.com/mishoo/UglifyJS2/issues/44
// https://github.com/mishoo/UglifyJS2/issues/1830
+ // https://github.com/mishoo/UglifyJS2/issues/1838
// that's an invalid AST.
// We fix it at this stage by moving the `var` outside the `for`.
if (node instanceof AST_For) {
@@ -2075,6 +2076,8 @@ merge(Compressor.prototype, {
node.init = block.body.pop();
block.body.push(node);
return in_list ? MAP.splice(block.body) : block;
+ } else if (node.init instanceof AST_SimpleStatement) {
+ node.init = node.init.body;
} else if (is_empty(node.init)) {
node.init = null;
}
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 7456f67..c702cfa 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1092,3 +1092,25 @@ issue_1830_2: {
}
expect_stdout: "1"
}
+
+issue_1838: {
+ options = {
+ join_vars: true,
+ loops: true,
+ unused: true,
+ }
+ beautify = {
+ beautify: true,
+ }
+ input: {
+ function f() {
+ var b = a;
+ while (c);
+ }
+ }
+ expect_exact: [
+ "function f() {",
+ " for (a; c; ) ;",
+ "}",
+ ]
+}
--
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