(doc)
| 63 | } |
| 64 | |
| 65 | function printDocToDebug(doc) { |
| 66 | /** @type Record<symbol, string> */ |
| 67 | const printedSymbols = Object.create(null); |
| 68 | /** @type Set<string> */ |
| 69 | const usedKeysForSymbols = new Set(); |
| 70 | return printDoc(flattenDoc(doc)); |
| 71 | |
| 72 | function printDoc(doc, index, parentParts) { |
| 73 | if (typeof doc === "string") { |
| 74 | return JSON.stringify(doc); |
| 75 | } |
| 76 | |
| 77 | if (Array.isArray(doc)) { |
| 78 | const printed = doc.map(printDoc).filter(Boolean); |
| 79 | return printed.length === 1 ? printed[0] : `[${printed.join(", ")}]`; |
| 80 | } |
| 81 | |
| 82 | if (doc.type === DOC_TYPE_LINE) { |
| 83 | const withBreakParent = |
| 84 | parentParts?.[index + 1]?.type === DOC_TYPE_BREAK_PARENT; |
| 85 | if (doc.literal) { |
| 86 | return withBreakParent |
| 87 | ? "literalline" |
| 88 | : "literallineWithoutBreakParent"; |
| 89 | } |
| 90 | if (doc.hard) { |
| 91 | return withBreakParent ? "hardline" : "hardlineWithoutBreakParent"; |
| 92 | } |
| 93 | if (doc.soft) { |
| 94 | return "softline"; |
| 95 | } |
| 96 | return "line"; |
| 97 | } |
| 98 | |
| 99 | if (doc.type === DOC_TYPE_BREAK_PARENT) { |
| 100 | const afterHardline = |
| 101 | parentParts?.[index - 1]?.type === DOC_TYPE_LINE && |
| 102 | parentParts[index - 1].hard; |
| 103 | return afterHardline ? undefined : "breakParent"; |
| 104 | } |
| 105 | |
| 106 | if (doc.type === DOC_TYPE_TRIM) { |
| 107 | return "trim"; |
| 108 | } |
| 109 | |
| 110 | if (doc.type === DOC_TYPE_INDENT) { |
| 111 | return "indent(" + printDoc(doc.contents) + ")"; |
| 112 | } |
| 113 | |
| 114 | if (doc.type === DOC_TYPE_ALIGN) { |
| 115 | return doc.n === Number.NEGATIVE_INFINITY |
| 116 | ? "dedentToRoot(" + printDoc(doc.contents) + ")" |
| 117 | : doc.n < 0 |
| 118 | ? "dedent(" + printDoc(doc.contents) + ")" |
| 119 | : doc.n.type === "root" |
| 120 | ? "markAsRoot(" + printDoc(doc.contents) + ")" |
| 121 | : "align(" + |
| 122 | JSON.stringify(doc.n) + |
no test coverage detected
searching dependent graphs…