MCPcopy
hub / github.com/prettier/prettier / printDanglingComments

Function printDanglingComments

src/main/comments/print.js:123–159  ·  view source on GitHub ↗

* @param {AstPath} path * @param {CommentPrintOptions & { * indent?: boolean, * marker?: symbol | string, * }} [danglingCommentsPrintOptions] * @returns {Doc}

(
  path,
  options,
  danglingCommentsPrintOptions = {},
)

Source from the content-addressed store, hash-verified

121 * @returns {Doc}
122 */
123function printDanglingComments(
124 path,
125 options,
126 danglingCommentsPrintOptions = {},
127) {
128 const {
129 indent: shouldIndent = false,
130 marker,
131 filter = returnTrue,
132 } = danglingCommentsPrintOptions;
133 const danglingComments = new Set(
134 path.node?.comments?.filter(
135 (comment) =>
136 !(
137 comment.leading ||
138 comment.trailing ||
139 comment.marker !== marker ||
140 !filter(comment)
141 ),
142 ),
143 );
144
145 if (danglingComments.size === 0) {
146 return "";
147 }
148
149 const parts = path
150 .map(
151 ({ node: comment }) =>
152 danglingComments.has(comment) ? printComment(path, options) : "",
153 "comments",
154 )
155 .filter(Boolean);
156
157 const doc = join(hardline, parts);
158 return shouldIndent ? indent([hardline, doc]) : doc;
159}
160
161/**
162@param {AstPath} path

Callers 15

genericPrintFunction · 0.90
printHeritageClausesFunction · 0.90
printForStatementFunction · 0.90
printClassBodyFunction · 0.90
printTernaryFunction · 0.90
printObjectFunction · 0.90
printEstreeFunction · 0.90
printBlockBodyFunction · 0.90
printIfStatementFunction · 0.90

Calls 5

joinFunction · 0.90
indentFunction · 0.90
filterFunction · 0.85
printCommentFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…