From 87b0ed3042178a13a95d1f957e8a12bc28f603f2 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Wed, 18 Jan 2017 13:12:57 -0600 Subject: [PATCH] Fix parens around anonymous functions (#297) --- src/fast-path.js | 1 + .../async_iteration/__snapshots__/jsfmt.spec.js.snap | 12 ++++++------ tests/function/__snapshots__/jsfmt.spec.js.snap | 3 +++ tests/function/function_expression.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 4 ++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/fast-path.js b/src/fast-path.js index ca3e73e76..de8b4572d 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -373,6 +373,7 @@ FPp.needsParens = function(assumeExpressionContext) { } switch (parent.type) { + case "ExpressionStatement": case "MemberExpression": case "TaggedTemplateExpression": case "UnaryExpression": diff --git a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap index 3d2a56d29..8173c5d8c 100644 --- a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap @@ -40,11 +40,11 @@ async function* delegate_yield() { } yield* inner(); } -async () => { +(async () => { for await (const x of delegate_yield()) { (x: void); // error: number ~> void } -}; +}); async function* delegate_return() { async function* inner() { @@ -197,13 +197,13 @@ async function* catch_return() { } } -async () => { +(async () => { catch_return().throw(\"\").then(({ value }) => { if (value !== undefined) { (value: void); // error: number ~> void } }); -}; +}); async function* yield_return() { try { @@ -214,12 +214,12 @@ async function* yield_return() { } } -async () => { +(async () => { yield_return().throw(\"\").then(({ value }) => { if (value !== undefined) { (value: void); // error: number ~> void } }); -}; +}); " `; diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap index 2cd319933..93ef91369 100644 --- a/tests/function/__snapshots__/jsfmt.spec.js.snap +++ b/tests/function/__snapshots__/jsfmt.spec.js.snap @@ -370,6 +370,7 @@ export default (function() {})(); (function() {})()\`\`; (function() {})\`\`; new (function() {}); +(function() {}) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (function() { }).length; @@ -383,6 +384,8 @@ export default (function() { })\`\`; new (function() { })(); +(function() { +}); " `; diff --git a/tests/function/function_expression.js b/tests/function/function_expression.js index e680a3d1a..aa9c6c35f 100644 --- a/tests/function/function_expression.js +++ b/tests/function/function_expression.js @@ -4,3 +4,4 @@ export default (function() {})(); (function() {})()``; (function() {})``; new (function() {}); +(function() {}) diff --git a/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap index b28d1c664..e6078c8e3 100644 --- a/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap @@ -112,14 +112,14 @@ var a0 = (x: mixed) => x !== null; var a1 = (x: mixed): %checks => x !== null; -(x): %checks => x !== null; +((x): %checks => x !== null); const insert_a_really_big_predicated_arrow_function_name_here = (x): %checks => x !== null; declare var x; x; -checks => 123; +(checks => 123); type checks = any;