diff --git a/src/printer.js b/src/printer.js index ffb22814..9bcfb542 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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": diff --git a/tests/typescript_nosemi/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_nosemi/__snapshots__/jsfmt.spec.js.snap index bc7b2c2e..6db6d27e 100644 --- a/tests/typescript_nosemi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_nosemi/__snapshots__/jsfmt.spec.js.snap @@ -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 } + `; diff --git a/tests/typescript_nosemi/interface.ts b/tests/typescript_nosemi/interface.ts index cfbd3c81..41c42a9c 100644 --- a/tests/typescript_nosemi/interface.ts +++ b/tests/typescript_nosemi/interface.ts @@ -4,3 +4,5 @@ interface MultiLine { x: string; y: string; } + +interface InlineMultiple { x: string; y: string } diff --git a/tests/typescript_nosemi/type.js b/tests/typescript_nosemi/type.js new file mode 100644 index 00000000..6acd0ad5 --- /dev/null +++ b/tests/typescript_nosemi/type.js @@ -0,0 +1 @@ +type A = {disabled?: boolean, error?: string}