[Pkg-javascript-commits] [uglifyjs] 165/190: Re-add parens after new expression in beautify mode
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:23 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.
commit 5c4cfaa0a75317582c979f9b50c1e562fbcfa40d
Author: Anthony Van de Gejuchte <anthonyvdgent at gmail.com>
Date: Sun Jun 12 17:34:05 2016 +0200
Re-add parens after new expression in beautify mode
---
lib/output.js | 4 +++-
test/mocha/new.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/lib/output.js b/lib/output.js
index 7ddee48..6eae2f1 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -1287,7 +1287,9 @@ function OutputStream(options) {
// self should be AST_New. decide if we want to show parens or not.
function need_constructor_parens(self, output) {
// Always print parentheses with arguments
- return self.args.length > 0;
+ if (self.args.length > 0) return true;
+
+ return output.option("beautify");
};
function best_of(a) {
diff --git a/test/mocha/new.js b/test/mocha/new.js
index 8c0f24b..083b996 100644
--- a/test/mocha/new.js
+++ b/test/mocha/new.js
@@ -2,7 +2,7 @@ var assert = require("assert");
var uglify = require("../../");
describe("New", function() {
- it("Should attach callback parens after some tokens", function() {
+ it("Should add trailing parentheses for new expressions with zero arguments in beautify mode", function() {
var tests = [
"new x(1);",
"new x;",
@@ -19,17 +19,17 @@ describe("New", function() {
];
var expected = [
"new x(1);",
- "new x;",
- "new (new x);",
+ "new x();",
+ "new new x()();",
"new function(foo) {\n this.foo = foo;\n}(1);",
- "new function(foo) {\n this.foo = foo;\n};",
+ "new function(foo) {\n this.foo = foo;\n}();",
"new function test(foo) {\n this.foo = foo;\n}(1);",
- "new function test(foo) {\n this.foo = foo;\n};",
- "new true;",
- "new 0;",
- "new (!0);",
+ "new function test(foo) {\n this.foo = foo;\n}();",
+ "new true();",
+ "new 0();",
+ "new (!0)();",
"new (bar = function(foo) {\n this.foo = foo;\n})(123);",
- "new (bar = function(foo) {\n this.foo = foo;\n});"
+ "new (bar = function(foo) {\n this.foo = foo;\n})();"
];
for (var i = 0; i < tests.length; i++) {
assert.strictEqual(
@@ -43,4 +43,46 @@ describe("New", function() {
);
}
});
+
+ it("Should not add trailing parentheses for new expressions with zero arguments in non-beautify mode", function() {
+ var tests = [
+ "new x(1);",
+ "new x;",
+ "new new x;",
+ "new (function(foo){this.foo=foo;})(1);",
+ "new (function(foo){this.foo=foo;})();",
+ "new (function test(foo){this.foo=foo;})(1);",
+ "new (function test(foo){this.foo=foo;})();",
+ "new true;",
+ "new (0);",
+ "new (!0);",
+ "new (bar = function(foo) {this.foo=foo;})(123);",
+ "new (bar = function(foo) {this.foo=foo;})();"
+ ];
+ var expected = [
+ "new x(1);",
+ "new x;",
+ "new(new x);",
+ "new function(foo){this.foo=foo}(1);",
+ "new function(foo){this.foo=foo};",
+ "new function test(foo){this.foo=foo}(1);",
+ "new function test(foo){this.foo=foo};",
+ "new true;",
+ "new 0;",
+ "new(!0);",
+ "new(bar=function(foo){this.foo=foo})(123);",
+ "new(bar=function(foo){this.foo=foo});"
+ ];
+ for (var i = 0; i < tests.length; i++) {
+ assert.strictEqual(
+ uglify.minify(tests[i], {
+ fromString: true,
+ output: {beautify: false},
+ compress: false,
+ mangle: false
+ }).code,
+ expected[i]
+ );
+ }
+ });
});
\ No newline at end of file
--
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