From 9c7253058970d7cb0e64250438d3ae4032818c48 Mon Sep 17 00:00:00 2001 From: James Long Date: Thu, 5 Jan 2017 15:11:40 -0500 Subject: [PATCH] Reduce duplicate code for printing intersection & union types --- src/printer.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/printer.js b/src/printer.js index 9afdb6c9..efbc0246 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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":