MCPcopy Index your code
hub / github.com/prettier/prettier / printDocToDebug

Function printDocToDebug

src/document/debug.js:65–222  ·  view source on GitHub ↗
(doc)

Source from the content-addressed store, hash-verified

63}
64
65function 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) +

Callers 1

formatDocFunction · 0.90

Calls 3

flattenDocFunction · 0.85
printDocFunction · 0.70
createMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…