[Pkg-javascript-commits] [uglifyjs] 269/491: remove hack in `collapse_vars` (#2457)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:43 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 246d9d4e83e857a26347944ada65fea95ad6381d
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Thu Nov 9 20:00:58 2017 +0800
remove hack in `collapse_vars` (#2457)
fixes #2456
---
lib/compress.js | 3 +--
test/mocha/minify.js | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 6354197..e457d80 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1062,7 +1062,7 @@ merge(Compressor.prototype, {
var found = false;
return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) {
if (found) return node;
- if (node === expr) {
+ if (node === expr || node.body === expr) {
found = true;
if (node instanceof AST_VarDef) {
drop_decl(node.name.definition());
@@ -1076,7 +1076,6 @@ merge(Compressor.prototype, {
case 0: return null;
case 1: return node.expressions[0];
}
- if (node instanceof AST_SimpleStatement && !node.body) return null;
}));
}
diff --git a/test/mocha/minify.js b/test/mocha/minify.js
index aed8f91..516541c 100644
--- a/test/mocha/minify.js
+++ b/test/mocha/minify.js
@@ -297,4 +297,36 @@ describe("minify", function() {
assert.strictEqual(result.code, "alert({bar:42});");
});
});
+
+ describe("collapse_vars", function() {
+ it("Should not produce invalid AST", function() {
+ var code = [
+ "function f(a) {",
+ " a = x();",
+ " return a;",
+ "}",
+ "f();",
+ ].join("\n");
+ var ast = Uglify.minify(code, {
+ compress: false,
+ mangle: false,
+ output: {
+ ast: true
+ },
+ }).ast;
+ assert.strictEqual(ast.TYPE, "Toplevel");
+ assert.strictEqual(ast.body.length, 2);
+ assert.strictEqual(ast.body[0].TYPE, "Defun");
+ assert.strictEqual(ast.body[0].body.length, 2);
+ assert.strictEqual(ast.body[0].body[0].TYPE, "SimpleStatement");
+ var stat = ast.body[0].body[0];
+ Uglify.minify(ast, {
+ compress: {
+ sequences: false
+ }
+ });
+ assert.ok(stat.body);
+ assert.strictEqual(stat.print_to_string(), "a=x()");
+ });
+ });
});
--
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