PARENS([ AST_Unary, AST_Undefined ], function(output){
var p = output.parent();
- return p instanceof AST_PropAccess && p.expression === this;
+ return p instanceof AST_PropAccess && p.expression === this
+ || p instanceof AST_New;
});
PARENS(AST_Seq, function(output){
// self should be AST_New. decide if we want to show parens or not.
function no_constructor_parens(self, output) {
- return self.args.length == 0 && !output.option("beautify");
+ return self.args.length == 0 && !output.option("beautify") ||
+ !(self.expression instanceof AST_SymbolRef ||
+ self.expression instanceof AST_Call ||
+ self.expression instanceof AST_Function ||
+ self.expression instanceof AST_Assign
+ );
};
function best_of(a) {
}
expect_exact: "new x(1);new x(1)(2);new x(1)(2)(3);new new x(1);new new x(1)(2);new new x(1)(2);(new new x(1))(2);"
}
+
+new_with_rewritten_true_value: {
+ options = { booleans: true }
+ input: {
+ new true;
+ }
+ expect_exact: "new(!0);"
+}
--- /dev/null
+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]
+ );
+ }
+ });
+});
\ No newline at end of file