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

Function printTrailingComment

lib/comments.ts:300–326  ·  view source on GitHub ↗
(commentPath: any, print: any)

Source from the content-addressed store, hash-verified

298}
299
300function printTrailingComment(commentPath: any, print: any) {
301 const comment = commentPath.getValue(commentPath);
302 n.Comment.assert(comment);
303
304 const loc = comment.loc;
305 const lines = loc && loc.lines;
306 const parts = [];
307
308 if (lines instanceof Lines) {
309 const fromPos = lines.skipSpaces(loc.start, true) || lines.firstPos();
310 const leadingSpace = lines.slice(fromPos, loc.start);
311
312 if (leadingSpace.length === 1) {
313 // If the leading space contains no newlines, then we want to
314 // preserve it exactly as we found it.
315 parts.push(leadingSpace);
316 } else {
317 // If the leading space contains newlines, then replace it
318 // with just that many newlines, sans all other spaces.
319 parts.push(new Array(leadingSpace.length).join("\n"));
320 }
321 }
322
323 parts.push(print(commentPath));
324
325 return concat(parts);
326}
327
328export function printComments(path: any, print: any) {
329 const value = path.getValue();

Callers 1

printCommentsFunction · 0.85

Calls 7

concatFunction · 0.90
getValueMethod · 0.80
skipSpacesMethod · 0.80
firstPosMethod · 0.80
joinMethod · 0.80
printFunction · 0.70
sliceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…