diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 09fbf017a..fd52d8d2c 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -3285,6 +3285,9 @@ function printFunctionParams(path, print, options, expandArg, printTypeParams) { !fun.rest; if (isFlowShorthandWithOneArg) { + if (options.arrowParens === "always") { + return concat(["(", concat(printed), ")"]); + } return concat(printed); } diff --git a/tests/flow_function_parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/flow_function_parentheses/__snapshots__/jsfmt.spec.js.snap index f193c2ffb..995d58e33 100644 --- a/tests/flow_function_parentheses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow_function_parentheses/__snapshots__/jsfmt.spec.js.snap @@ -34,6 +34,23 @@ const selectorByPath: Path => SomethingSelector< `; +exports[`single.js 3`] = ` +const selectorByPath: + Path + => SomethingSelector< + SomethingUEditorContextType, + SomethingUEditorContextType, + SomethingBulkValue +> = memoizeWithArgs(/* ... */) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const selectorByPath: (Path) => SomethingSelector< + SomethingUEditorContextType, + SomethingUEditorContextType, + SomethingBulkValue +> = memoizeWithArgs(/* ... */); + +`; + exports[`test.js 1`] = ` type Banana = { eat: string => boolean, @@ -219,3 +236,96 @@ interface F { type ExtractType = (B) => D; `; + +exports[`test.js 3`] = ` +type Banana = { + eat: string => boolean, +}; + +type Hex = {n: 0x01}; + +type T = { method: (a) => void }; + +type T = { method(a): void }; + +declare class X { method(a): void } + +declare function f(a): void; + +var f: (a) => void; + +interface F { m(string): number } + +interface F { m: (string) => number } + +function f(o: { f: (string) => void }) {} + +function f(o: { f(string): void }) {} + +type f = (...arg) => void; + +type f = (/* comment */ arg) => void; + +type f = (arg /* comment */) => void; + +type f = (?arg) => void; + +class X { + constructor( + ideConnectionFactory: child_process$ChildProcess => FlowIDEConnection = + defaultIDEConnectionFactory, + ) { + } +} + +interface F { + ideConnectionFactoryLongLongLong: (child_process$ChildProcess) => FlowIDEConnection +} + +type ExtractType = (B) => D +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type Banana = { + eat: (string) => boolean +}; + +type Hex = { n: 0x01 }; + +type T = { method: (a) => void }; + +type T = { method(a): void }; + +declare class X { method(a): void } + +declare function f(a): void; + +var f: (a) => void; + +interface F { m(string): number } + +interface F { m: (string) => number } + +function f(o: { f: (string) => void }) {} + +function f(o: { f(string): void }) {} + +type f = (...arg) => void; + +type f = (/* comment */ arg) => void; + +type f = (arg /* comment */) => void; + +type f = (?arg) => void; + +class X { + constructor( + ideConnectionFactory: (child_process$ChildProcess) => FlowIDEConnection = defaultIDEConnectionFactory + ) {} +} + +interface F { + ideConnectionFactoryLongLongLong: (child_process$ChildProcess) => FlowIDEConnection; +} + +type ExtractType = (B) => D; + +`; diff --git a/tests/flow_function_parentheses/jsfmt.spec.js b/tests/flow_function_parentheses/jsfmt.spec.js index 425bb9ff4..d0170fdab 100644 --- a/tests/flow_function_parentheses/jsfmt.spec.js +++ b/tests/flow_function_parentheses/jsfmt.spec.js @@ -1,2 +1,3 @@ run_spec(__dirname, ["flow", "babylon"]); run_spec(__dirname, ["flow", "babylon"], { trailingComma: "all" }); +run_spec(__dirname, ["flow", "babylon"], { arrowParens: "always" });