fix(typescript): print semi with inline interfaces/types, fixes #1930 (#1936)

master
Lucas Azzola 2017-06-03 22:18:59 +10:00 committed by Christopher Chedeau
parent f56f9e5e8f
commit 2ef169eb67
4 changed files with 22 additions and 9 deletions

View File

@ -816,9 +816,16 @@ function genericPrintNoParens(path, options, print, args) {
case "TSInterfaceBody":
case "TSTypeLiteral": {
const isTypeAnnotation = n.type === "ObjectTypeAnnotation";
const shouldBreak =
n.type !== "ObjectPattern" &&
util.hasNewlineInRange(
options.originalText,
util.locStart(n),
util.locEnd(n)
);
const separator = n.type === "TSInterfaceBody" ||
n.type === "TSTypeLiteral"
? semi
? shouldBreak ? semi : ";"
: ",";
const fields = [];
const leftBrace = n.exact ? "{|" : "{";
@ -921,14 +928,6 @@ function genericPrintNoParens(path, options, print, args) {
return content;
}
const shouldBreak =
n.type !== "ObjectPattern" &&
util.hasNewlineInRange(
options.originalText,
util.locStart(n),
util.locEnd(n)
);
return group(content, { shouldBreak });
}
case "PropertyPattern":

View File

@ -7,6 +7,8 @@ interface MultiLine {
x: string;
y: string;
}
interface InlineMultiple { x: string; y: string }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
interface Inline { x: string }
@ -15,4 +17,13 @@ interface MultiLine {
y: string
}
interface InlineMultiple { x: string; y: string }
`;
exports[`type.js 1`] = `
type A = {disabled?: boolean, error?: string}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type A = { disabled?: boolean; error?: string }
`;

View File

@ -4,3 +4,5 @@ interface MultiLine {
x: string;
y: string;
}
interface InlineMultiple { x: string; y: string }

View File

@ -0,0 +1 @@
type A = {disabled?: boolean, error?: string}