Reduce duplicate code for printing intersection & union types

master
James Long 2017-01-05 15:11:40 -05:00
parent 5c39dc02e6
commit 9c72530589
1 changed files with 6 additions and 10 deletions

View File

@ -1403,20 +1403,16 @@ else
path.call(print, "id"),
path.call(print, "typeParameters")
]);
case "IntersectionTypeAnnotation": {
const types = path.map(print, "types")
return group(concat([
types[0],
indent(options.tabWidth,
concat(types.slice(1).map(t => concat([" &", line, t]))))
]));
}
case "IntersectionTypeAnnotation":
case "UnionTypeAnnotation": {
const types = path.map(print, "types")
const op = n.type === "IntersectionTypeAnnotation" ? "&" : "|";
return group(concat([
types[0],
indent(options.tabWidth,
concat(types.slice(1).map(t => concat([" |", line, t]))))
indent(
options.tabWidth,
concat(types.slice(1).map(t => concat([" ", op, line, t])))
)
]));
}
case "NullableTypeAnnotation":