Add ability for flow generics to break (#1041)
While looking at an instability on the React codebase ( ba1299acc2 (diff-2550aa3d377452ae29361f5e53c51c10)
), I realized that we don't let them break which makes the code look weird.
So I added the ability for them to break :)
master
parent
82d6e0b4ab
commit
a502bf9f45
|
@ -1574,7 +1574,7 @@ function genericPrintNoParens(path, options, print) {
|
||||||
|
|
||||||
parts.push(path.call(print, "typeParameters"));
|
parts.push(path.call(print, "typeParameters"));
|
||||||
|
|
||||||
parts.push(group(printFunctionParams(path, print, options)));
|
parts.push(printFunctionParams(path, print, options));
|
||||||
|
|
||||||
// The returnType is not wrapped in a TypeAnnotation, so the colon
|
// The returnType is not wrapped in a TypeAnnotation, so the colon
|
||||||
// needs to be added separately.
|
// needs to be added separately.
|
||||||
|
@ -1587,7 +1587,7 @@ function genericPrintNoParens(path, options, print) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return concat(parts);
|
return group(concat(parts));
|
||||||
case "FunctionTypeParam":
|
case "FunctionTypeParam":
|
||||||
return concat([
|
return concat([
|
||||||
path.call(print, "name"),
|
path.call(print, "name"),
|
||||||
|
@ -1766,8 +1766,28 @@ function genericPrintNoParens(path, options, print) {
|
||||||
")"
|
")"
|
||||||
]);
|
]);
|
||||||
case "TypeParameterDeclaration":
|
case "TypeParameterDeclaration":
|
||||||
case "TypeParameterInstantiation":
|
case "TypeParameterInstantiation": {
|
||||||
|
const shouldInline =
|
||||||
|
n.params.length === 1 &&
|
||||||
|
n.params[0].type === "ObjectTypeAnnotation";
|
||||||
|
|
||||||
|
if (shouldInline) {
|
||||||
return concat(["<", join(", ", path.map(print, "params")), ">"]);
|
return concat(["<", join(", ", path.map(print, "params")), ">"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return group(concat([
|
||||||
|
"<",
|
||||||
|
indent(
|
||||||
|
options.tabWidth,
|
||||||
|
concat([
|
||||||
|
softline,
|
||||||
|
join(concat([",", line]), path.map(print, "params")),
|
||||||
|
])
|
||||||
|
),
|
||||||
|
softline,
|
||||||
|
">"
|
||||||
|
]));
|
||||||
|
}
|
||||||
case "TypeParameter":
|
case "TypeParameter":
|
||||||
switch (n.variance) {
|
switch (n.variance) {
|
||||||
case "plus":
|
case "plus":
|
||||||
|
|
|
@ -12,7 +12,12 @@ declare var $React: $Exports<\\"react\\">; // fake import
|
||||||
// Strawman: revised definition of $jsx (alternatively, React.Element).
|
// Strawman: revised definition of $jsx (alternatively, React.Element).
|
||||||
// Using bounded poly to specify a constraint on a type parameter, and
|
// Using bounded poly to specify a constraint on a type parameter, and
|
||||||
// existentials to elide type arguments.
|
// existentials to elide type arguments.
|
||||||
type _ReactElement<DefaultProps, Props, Config: $Diff<Props, DefaultProps>, C: $React.Component<DefaultProps, Props, any>> = $React.Element<Config>;
|
type _ReactElement<
|
||||||
|
DefaultProps,
|
||||||
|
Props,
|
||||||
|
Config: $Diff<Props, DefaultProps>,
|
||||||
|
C: $React.Component<DefaultProps, Props, any>
|
||||||
|
> = $React.Element<Config>;
|
||||||
type $jsx<C> = _ReactElement<*, *, *, C>;
|
type $jsx<C> = _ReactElement<*, *, *, C>;
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -88,9 +88,9 @@ declare class Promise<R> {
|
||||||
static all<T>(promises: Array<?Promise<T> | T>): Promise<Array<T>>,
|
static all<T>(promises: Array<?Promise<T> | T>): Promise<Array<T>>,
|
||||||
static race<T>(promises: Array<Promise<T>>): Promise<T>,
|
static race<T>(promises: Array<Promise<T>>): Promise<T>,
|
||||||
|
|
||||||
static allObject<T: Object>(promisesByKey: T): Promise<{
|
static allObject<T: Object>(
|
||||||
[key: $Keys<T>]: any
|
promisesByKey: T
|
||||||
}>
|
): Promise<{ [key: $Keys<T>]: any }>
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`break.js 1`] = `
|
||||||
|
"var X = {
|
||||||
|
perform: function<
|
||||||
|
A, B, C, D, E, F, G,
|
||||||
|
T: (a: A, b: B, c: C, d: D, e: E, f: F) => G // eslint-disable-line space-before-function-paren
|
||||||
|
>(
|
||||||
|
method: T, scope: any,
|
||||||
|
a: A, b: B, c: C, d: D, e: E, f: F,
|
||||||
|
): G {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
var X = {
|
||||||
|
perform: function<
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
D,
|
||||||
|
E,
|
||||||
|
F,
|
||||||
|
G,
|
||||||
|
T: (a: A, b: B, c: C, d: D, e: E, f: F) => G // eslint-disable-line space-before-function-paren
|
||||||
|
>(method: T, scope: any, a: A, b: B, c: C, d: D, e: E, f: F): G {}
|
||||||
|
};
|
||||||
|
"
|
||||||
|
`;
|
|
@ -0,0 +1,10 @@
|
||||||
|
var X = {
|
||||||
|
perform: function<
|
||||||
|
A, B, C, D, E, F, G,
|
||||||
|
T: (a: A, b: B, c: C, d: D, e: E, f: F) => G // eslint-disable-line space-before-function-paren
|
||||||
|
>(
|
||||||
|
method: T, scope: any,
|
||||||
|
a: A, b: B, c: C, d: D, e: E, f: F,
|
||||||
|
): G {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname);
|
Loading…
Reference in New Issue