Fix uglify attempting to rewrite invalid new expressions

This commit is contained in:
Anthony Van de Gejuchte
2016-06-07 01:33:13 +02:00
committed by Richard van Velzen
parent 5cb5305cf3
commit 8287ef6781
3 changed files with 50 additions and 2 deletions

34
test/mocha/new.js Normal file
View File

@@ -0,0 +1,34 @@
var assert = require("assert");
var uglify = require("../../");
describe("New", function() {
it("Should attach callback parens after some tokens", function() {
var tests = [
"new x(1);",
"new (function(foo){this.foo=foo;})(1);",
"new true;",
"new (0);",
"new (!0);",
"new (bar = function(foo) {this.foo=foo;})(123);"
];
var expected = [
"new x(1);",
"new function(foo) {\n this.foo = foo;\n}(1);",
"new true;",
"new 0;",
"new (!0);",
"new (bar = function(foo) {\n this.foo = foo;\n})(123);"
];
for (var i = 0; i < tests.length; i++) {
assert.strictEqual(
uglify.minify(tests[i], {
fromString: true,
output: {beautify: true},
compress: false,
mangle: false
}).code,
expected[i]
);
}
});
});