MCPcopy
hub / github.com/prettier/prettier / print

Function print

src/language-js/print/index.js:60–97  ·  view source on GitHub ↗

* @param {AstPath} path * @param {*} options * @param {*} print * @param {*} [args] * @returns {Doc}

(path, options, print, args)

Source from the content-addressed store, hash-verified

58 * @returns {Doc}
59 */
60function print(path, options, print, args) {
61 if (path.isRoot) {
62 options.__onHtmlBindingRoot?.(path.node, options);
63 }
64
65 const { node } = path;
66
67 let doc = isIgnored(path)
68 ? printIgnored(path, options)
69 : printWithoutParentheses(path, options, print, args);
70 if (!doc) {
71 return "";
72 }
73
74 if (shouldPrintDirectly(node)) {
75 return doc;
76 }
77
78 doc = printCommentsForFunction(path, options, doc);
79
80 const decoratorsDoc =
81 // `ClassExpression` prints own decorators
82 node.type !== "ClassExpression" && isNonEmptyArray(node.decorators)
83 ? printDecorators(path, options, print)
84 : "";
85
86 const needsParens = needsParentheses(path, options);
87
88 if (!decoratorsDoc && !needsParens) {
89 return doc;
90 }
91
92 return inheritLabel(doc, (doc) => [
93 needsParens ? "(" : "",
94 decoratorsDoc ? group([decoratorsDoc, doc]) : doc,
95 needsParens ? ")" : "",
96 ]);
97}
98
99function printCommentsForFunction(path, options, doc) {
100 const { node } = path;

Callers 15

printSuperClassFunction · 0.70
printClassPropertyFunction · 0.70
printClauseFunction · 0.70
printNamedTupleMemberFunction · 0.70
printCallArgumentsFunction · 0.70
printExpressionStatementFunction · 0.70
printOpaqueTypeFunction · 0.70
printForStatementFunction · 0.70
printTypeParametersFunction · 0.70
printTypeParameterFunction · 0.70

Calls 9

printIgnoredFunction · 0.90
printDecoratorsFunction · 0.90
inheritLabelFunction · 0.90
groupFunction · 0.90
printWithoutParenthesesFunction · 0.85
printCommentsForFunctionFunction · 0.85
isNonEmptyArrayFunction · 0.85
needsParenthesesFunction · 0.85
isIgnoredFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…