diff --git a/src/language-js/print/array.js b/src/language-js/print/array.js index 8a87305bb..3f6f9fae6 100644 --- a/src/language-js/print/array.js +++ b/src/language-js/print/array.js @@ -209,4 +209,4 @@ function printArrayItemsConcisely(path, options, print, trailingComma) { return fill(parts); } -export { printArray, printArrayItems, isConciselyPrintedArray }; +export { printArray, isConciselyPrintedArray }; diff --git a/src/language-js/print/enum.js b/src/language-js/print/enum.js index 8202654f8..0ad924cc5 100644 --- a/src/language-js/print/enum.js +++ b/src/language-js/print/enum.js @@ -1,36 +1,8 @@ -import { hardline, softline, group, indent } from "../../document/builders.js"; -import { printDanglingComments } from "../../main/comments.js"; -import { shouldPrintComma } from "../utils/index.js"; -import { printArrayItems } from "./array.js"; import { printTypeScriptModifiers } from "./misc.js"; - -function printEnumMemberList(path, print, options) { - const { - node: { members, hasUnknownMembers }, - } = path; - - if (members.length === 0 && !hasUnknownMembers) { - return [printDanglingComments(path, options), softline]; - } - - return [ - indent([ - ...(members.length > 0 - ? [ - hardline, - printArrayItems(path, options, "members", print), - hasUnknownMembers || shouldPrintComma(options) ? "," : "", - ] - : []), - ...(hasUnknownMembers ? [hardline, "..."] : []), - ]), - printDanglingComments(path, options, /* sameIndent */ true), - hardline, - ]; -} +import { printObject } from "./object.js"; function printEnumMembers(path, print, options) { - return group(["{", printEnumMemberList(path, print, options), "}"]); + return printObject(path, options, print); } /* diff --git a/src/language-js/print/object.js b/src/language-js/print/object.js index e3b575c09..054d89c6c 100644 --- a/src/language-js/print/object.js +++ b/src/language-js/print/object.js @@ -33,8 +33,14 @@ function printObject(path, options, print) { const { node } = path; const isTypeAnnotation = node.type === "ObjectTypeAnnotation"; + const isEnumBody = + node.type === "TSEnumDeclaration" || + node.type === "EnumBooleanBody" || + node.type === "EnumNumberBody" || + node.type === "EnumStringBody" || + node.type === "EnumSymbolBody"; const fields = [ - node.type === "TSTypeLiteral" + node.type === "TSTypeLiteral" || isEnumBody ? "members" : node.type === "TSInterfaceBody" ? "body" @@ -72,6 +78,7 @@ function printObject(path, options, print) { path.getName() === "body"; const shouldBreak = node.type === "TSInterfaceBody" || + isEnumBody || isFlowInterfaceLikeBody || (node.type === "ObjectPattern" && parent.type !== "FunctionDeclaration" && @@ -124,7 +131,7 @@ function printObject(path, options, print) { return result; }); - if (node.inexact) { + if (node.inexact || node.hasUnknownMembers) { let printed; if (hasComment(node, CommentCheckFlags.Dangling)) { const hasLineComments = hasComment(node, CommentCheckFlags.Line); @@ -151,6 +158,7 @@ function printObject(path, options, print) { const canHaveTrailingSeparator = !( node.inexact || + node.hasUnknownMembers || (lastElem && (lastElem.type === "RestElement" || ((lastElem.type === "TSPropertySignature" ||