From e6092bcf3922477330c6df6f5137c081ac011da2 Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Thu, 1 Sep 2016 09:35:31 +0200 Subject: [PATCH 1/2] Don't parenthesize arrow functions in parameter lists --- lib/output.js | 2 +- test/compress/harmony.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/output.js b/lib/output.js index d0238da8..6cf031bf 100644 --- a/lib/output.js +++ b/lib/output.js @@ -944,7 +944,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); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 122069dd..77c37b84 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -390,4 +390,12 @@ regression_cannot_use_of: { x.of; foo(); /* Label statement missing? No prob. */ } -} \ No newline at end of file +} + +fat_arrow_as_param: { + input: { + foo(x => x); + foo(x => x, y => y); + } + expect_exact: "foo(x=>x);foo(x=>x,y=>y);" +} From fd38acae43533f3b0e9747b0da8d4b7a857a685f Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Thu, 1 Sep 2016 10:05:59 +0200 Subject: [PATCH 2/2] Add parenthesis around sequences in arrow bodies --- lib/output.js | 1 + test/compress/harmony.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/output.js b/lib/output.js index 6cf031bf..81712d21 100644 --- a/lib/output.js +++ b/lib/output.js @@ -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) ; }); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 77c37b84..e13b27e0 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -396,6 +396,9 @@ 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);" + expect_exact: "foo(x=>x);foo(x=>x,y=>y);foo(x=>(x,x));foo(x=>(x,x),y=>(y,y));" }