diff options
author | Anthony Van de Gejuchte <anthonyvdgent@gmail.com> | 2016-06-12 17:34:05 +0200 |
---|---|---|
committer | Richard van Velzen <rvanvelzen@experty.com> | 2016-06-12 20:03:48 +0200 |
commit | 5c4cfaa0a75317582c979f9b50c1e562fbcfa40d (patch) | |
tree | a070bfffc9db51dc90e45fd2d0319c7b44db26cc /test/mocha/new.js | |
parent | bb9c9707aa6b4c625ad985798aea879080411ce1 (diff) | |
download | tracifyjs-5c4cfaa0a75317582c979f9b50c1e562fbcfa40d.tar.gz tracifyjs-5c4cfaa0a75317582c979f9b50c1e562fbcfa40d.zip |
Re-add parens after new expression in beautify mode
Diffstat (limited to 'test/mocha/new.js')
-rw-r--r-- | test/mocha/new.js | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/test/mocha/new.js b/test/mocha/new.js index 8c0f24bc..083b9964 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 |