aboutsummaryrefslogtreecommitdiff
path: root/test/mocha
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-11-09 20:00:58 +0800
committerGitHub <noreply@github.com>2017-11-09 20:00:58 +0800
commit246d9d4e83e857a26347944ada65fea95ad6381d (patch)
treed7c38d6d37bfc71323032b0adca416b429a0e741 /test/mocha
parent4c0b0177b6fa556c31f0099c6d52a4ad4f670ba3 (diff)
downloadtracifyjs-246d9d4e83e857a26347944ada65fea95ad6381d.tar.gz
tracifyjs-246d9d4e83e857a26347944ada65fea95ad6381d.zip
remove hack in `collapse_vars` (#2457)
fixes #2456
Diffstat (limited to 'test/mocha')
-rw-r--r--test/mocha/minify.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/mocha/minify.js b/test/mocha/minify.js
index aed8f915..516541c3 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()");
+ });
+ });
});