MCPcopy
hub / github.com/prettier/prettier / callPluginPrintFunction

Function callPluginPrintFunction

src/main/ast-to-doc.js:104–144  ·  view source on GitHub ↗
(path, options, printPath, args, embeds)

Source from the content-addressed store, hash-verified

102}
103
104function callPluginPrintFunction(path, options, printPath, args, embeds) {
105 const { node } = path;
106 const { printer } = options;
107
108 let doc;
109
110 // Escape hatch
111 if (printer.hasPrettierIgnore?.(path)) {
112 doc = printIgnored(path, options, printPath, args);
113 } else if (embeds.has(node)) {
114 doc = embeds.get(node);
115 } else {
116 doc = printer.print(path, options, printPath, args);
117 }
118
119 switch (node) {
120 case options.cursorNode:
121 doc = inheritLabel(doc, (doc) => [cursor, doc, cursor]);
122 break;
123 case options.nodeBeforeCursor:
124 doc = inheritLabel(doc, (doc) => [doc, cursor]);
125 break;
126 case options.nodeAfterCursor:
127 doc = inheritLabel(doc, (doc) => [cursor, doc]);
128 break;
129 }
130
131 // We let JSXElement print its comments itself because it adds () around
132 // UnionTypeAnnotation has to align the child without the comments
133 if (
134 printer.printComment &&
135 isNonEmptyArray(node.comments) &&
136 !printer.willPrintOwnComments?.(path, options)
137 ) {
138 // printComments will call the plugin print function and check for
139 // comments to print
140 doc = printComments(path, doc, options);
141 }
142
143 return doc;
144}
145
146async function prepareToPrint(ast, options) {
147 const comments = ast.comments ?? [];

Callers 2

printAstToDocFunction · 0.85
mainPrintInternalFunction · 0.85

Calls 6

inheritLabelFunction · 0.90
printCommentsFunction · 0.90
isNonEmptyArrayFunction · 0.85
printIgnoredFunction · 0.70
printMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…