Don't parenthesize arrow functions in parameter lists

This commit is contained in:
Richard van Velzen
2016-09-01 09:35:31 +02:00
parent 7f6b5d662b
commit 1db50c3b16
2 changed files with 14 additions and 2 deletions

View File

@@ -597,6 +597,7 @@ function OutputStream(options) {
|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
* ==> 20 (side effect, set a := 10 and b := 20) */
|| p instanceof AST_Arrow // x => (x, x)
;
});
@@ -944,7 +945,7 @@ function OutputStream(options) {
var parent = output.parent();
var needs_parens = parent instanceof AST_Binary ||
parent instanceof AST_Unary ||
parent instanceof AST_Call;
(parent instanceof AST_Call && self === parent.expression);
if (needs_parens) { output.print("(") }
if (self.argnames.length === 1 && self.argnames[0] instanceof AST_Symbol && !self.argnames[0].default) {
self.argnames[0].print(output);

View File

@@ -391,3 +391,14 @@ regression_cannot_use_of: {
foo(); /* Label statement missing? No prob. */
}
}
fat_arrow_as_param: {
input: {
foo(x => x);
foo(x => x, y => y);
foo(x => (x, x));
foo(x => (x, x), y => (y, y));
}
expect_exact: "foo(x=>x);foo(x=>x,y=>y);foo(x=>(x,x));foo(x=>(x,x),y=>(y,y));"
}