Inline nullable in flow generics (#1426)

This commit is contained in:
Brian Ng authored and Christopher Chedeau committed 2017-04-26 09:27:06 -07:00
1 parent fff743024c
commit 9c826c2ed5
4 files changed
+60 -3

No files matched your search

+3 -1
View File
@@ -1852,7 +1852,9 @@ function genericPrintNoParens(path, options, print, args) {
case "TypeParameterDeclaration":
case "TypeParameterInstantiation": {
const shouldInline =
n.params.length === 1 && n.params[0].type === "ObjectTypeAnnotation";
n.params.length === 1 &&
(n.params[0].type === "ObjectTypeAnnotation" ||
n.params[0].type === "NullableTypeAnnotation");
if (shouldInline) {
return concat(["<", join(", ", path.map(print, "params")), ">"]);
@@ -54,6 +54,52 @@ var X = {
`;
exports[`nullable.js 1`] = `
function formatEntireFile(
fileVersion: FileVersion,
range: atom$Range,
): Promise<?{
newCursor?: number,
formatted: string,
}> {}
function foo(): Promise<?boolean> {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function formatEntireFile(
fileVersion: FileVersion,
range: atom$Range
): Promise<?{
newCursor?: number,
formatted: string
}> {}
function foo(): Promise<?boolean> {}
`;
exports[`nullable.js 2`] = `
function formatEntireFile(
fileVersion: FileVersion,
range: atom$Range,
): Promise<?{
newCursor?: number,
formatted: string,
}> {}
function foo(): Promise<?boolean> {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function formatEntireFile(
fileVersion: FileVersion,
range: atom$Range,
): Promise<?{
newCursor?: number,
formatted: string,
}> {}
function foo(): Promise<?boolean> {}
`;
exports[`trailing.js 1`] = `
type State = {
errors: Immutable.Map<
+2 -2
View File
@@ -1,2 +1,2 @@
run_spec(__dirname);
run_spec(__dirname, { trailingComma: 'all' });
run_spec(__dirname, null, ["babylon"]);
run_spec(__dirname, { trailingComma: 'all' }, ["babylon"]);
+9
View File
@@ -0,0 +1,9 @@
function formatEntireFile(
fileVersion: FileVersion,
range: atom$Range,
): Promise<?{
newCursor?: number,
formatted: string,
}> {}
function foo(): Promise<?boolean> {}