Print parens in FunctionTypeAnnotation when arrowParens is "always" (#3616)

* add test case

* print parens in function type annotation
This commit is contained in:
Lucas Duailibe authored and Christopher Chedeau committed 2017-12-31 16:01:21 +01:00
1 parent 6c0dd74518
commit 51744e1008
3 files changed
+114

No files matched your search

+3
View File
@@ -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);
}
@@ -34,6 +34,23 @@ const selectorByPath: Path => SomethingSelector<
`;
exports[`single.js 3`] = `
const selectorByPath:
Path
=> SomethingSelector<
SomethingUEditorContextType,
SomethingUEditorContextType,
SomethingBulkValue<string>
> = memoizeWithArgs(/* ... */)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const selectorByPath: (Path) => SomethingSelector<
SomethingUEditorContextType,
SomethingUEditorContextType,
SomethingBulkValue<string>
> = memoizeWithArgs(/* ... */);
`;
exports[`test.js 1`] = `
type Banana = {
eat: string => boolean,
@@ -219,3 +236,96 @@ interface F {
type ExtractType = <A>(B<C>) => 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 = <A>(B<C>) => 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 = <A>(B<C>) => D;
`;
@@ -1,2 +1,3 @@
run_spec(__dirname, ["flow", "babylon"]);
run_spec(__dirname, ["flow", "babylon"], { trailingComma: "all" });
run_spec(__dirname, ["flow", "babylon"], { arrowParens: "always" });