MCPcopy
hub / github.com/benjamn/recast / printComments

Function printComments

lib/comments.ts:328–363  ·  view source on GitHub ↗
(path: any, print: any)

Source from the content-addressed store, hash-verified

326}
327
328export function printComments(path: any, print: any) {
329 const value = path.getValue();
330 const innerLines = print(path);
331 const comments =
332 n.Node.check(value) && types.getFieldValue(value, "comments");
333
334 if (!comments || comments.length === 0) {
335 return innerLines;
336 }
337
338 const leadingParts: any[] = [];
339 const trailingParts = [innerLines];
340
341 path.each(function (commentPath: any) {
342 const comment = commentPath.getValue();
343 const leading = types.getFieldValue(comment, "leading");
344 const trailing = types.getFieldValue(comment, "trailing");
345
346 if (
347 leading ||
348 (trailing &&
349 !(
350 n.Statement.check(value) ||
351 comment.type === "Block" ||
352 comment.type === "CommentBlock"
353 ))
354 ) {
355 leadingParts.push(printLeadingComment(commentPath, print));
356 } else if (trailing) {
357 trailingParts.push(printTrailingComment(commentPath, print));
358 }
359 }, "comments");
360
361 leadingParts.push.apply(leadingParts, trailingParts);
362 return concat(leadingParts);
363}

Callers 2

printFunction · 0.90
printGenericallyFunction · 0.90

Calls 6

concatFunction · 0.90
printLeadingCommentFunction · 0.85
printTrailingCommentFunction · 0.85
getValueMethod · 0.80
eachMethod · 0.80
printFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…