[Pkg-javascript-commits] [uglifyjs] 157/190: Fix uglify attempting to rewrite invalid new expressions
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:22 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 8287ef67810f2332459fa157b26e556f55b36b98
Author: Anthony Van de Gejuchte <anthonyvdgent at gmail.com>
Date: Tue Jun 7 01:33:13 2016 +0200
Fix uglify attempting to rewrite invalid new expressions
---
lib/output.js | 10 ++++++++--
test/compress/new.js | 8 ++++++++
test/mocha/new.js | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/lib/output.js b/lib/output.js
index f878758..f5ca026 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -515,7 +515,8 @@ function OutputStream(options) {
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){
@@ -1283,7 +1284,12 @@ function OutputStream(options) {
// 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) {
diff --git a/test/compress/new.js b/test/compress/new.js
index 4b2c51c..d956ae2 100644
--- a/test/compress/new.js
+++ b/test/compress/new.js
@@ -10,3 +10,11 @@ new_statement: {
}
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);"
+}
diff --git a/test/mocha/new.js b/test/mocha/new.js
new file mode 100644
index 0000000..7e7aea7
--- /dev/null
+++ b/test/mocha/new.js
@@ -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]
+ );
+ }
+ });
+});
\ 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