MCPcopy Index your code
hub / github.com/prettier/prettier / isOwnLineComment

Function isOwnLineComment

src/main/comments/attach.js:265–286  ·  view source on GitHub ↗
(text, options, decoratedComments, commentIndex)

Source from the content-addressed store, hash-verified

263
264const isAllEmptyAndNoLineBreak = (text) => !/[\S\n\u2028\u2029]/.test(text);
265function isOwnLineComment(text, options, decoratedComments, commentIndex) {
266 const { comment, precedingNode } = decoratedComments[commentIndex];
267 const { locStart, locEnd } = options;
268 let start = locStart(comment);
269
270 if (precedingNode) {
271 // Find first comment on the same line
272 for (let index = commentIndex - 1; index >= 0; index--) {
273 const { comment, precedingNode: currentCommentPrecedingNode } =
274 decoratedComments[index];
275 if (
276 currentCommentPrecedingNode !== precedingNode ||
277 !isAllEmptyAndNoLineBreak(text.slice(locEnd(comment), start))
278 ) {
279 break;
280 }
281 start = locStart(comment);
282 }
283 }
284
285 return hasNewline(text, start, { backwards: true });
286}
287
288function isEndOfLineComment(text, options, decoratedComments, commentIndex) {
289 const { comment, followingNode } = decoratedComments[commentIndex];

Callers 1

attachCommentsFunction · 0.85

Calls 4

isAllEmptyAndNoLineBreakFunction · 0.85
hasNewlineFunction · 0.85
locStartFunction · 0.50
locEndFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…