aboutsummaryrefslogtreecommitdiff
path: root/lib/output.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output.js')
-rw-r--r--lib/output.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/output.js b/lib/output.js
index a6d0d0da..7bb27d9b 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -678,7 +678,7 @@ function OutputStream(options) {
// same goes for an object literal, because otherwise it would be
// interpreted as a block of code.
function needs_parens_obj(output) {
- return !output.has_parens() && first_in_statement(output);
+ return !output.has_parens() && first_in_statement(output, true);
}
PARENS(AST_Object, needs_parens_obj);
@@ -691,6 +691,8 @@ function OutputStream(options) {
var p = output.parent();
// [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
return p instanceof AST_Array
+ // () => (foo, bar)
+ || p instanceof AST_Arrow && p.value === this
// await (foo, bar)
|| p instanceof AST_Await
// 1 + (2, 3) + 4 ==> 8
@@ -798,6 +800,9 @@ function OutputStream(options) {
// !(a = false) → true
if (p instanceof AST_Unary) return true;
}
+ PARENS(AST_Arrow, function(output) {
+ return needs_parens_assign_cond(this, output);
+ });
PARENS(AST_Assign, function(output) {
if (needs_parens_assign_cond(this, output)) return true;
// v8 parser bug => workaround
@@ -985,6 +990,25 @@ function OutputStream(options) {
});
/* -----[ functions ]----- */
+ DEFPRINT(AST_Arrow, function(output) {
+ var self = this;
+ if (self.argnames.length == 1 && self.argnames[0] instanceof AST_SymbolFunarg) {
+ self.argnames[0].print(output);
+ } else output.with_parens(function() {
+ self.argnames.forEach(function(arg, i) {
+ if (i) output.comma();
+ arg.print(output);
+ });
+ });
+ output.space();
+ output.print("=>");
+ output.space();
+ if (self.value) {
+ self.value.print(output);
+ } else {
+ print_braced(self, output, true);
+ }
+ });
function print_lambda(self, output) {
if (self.name) {
output.space();