MCPcopy Index your code
hub / github.com/nodejs/node / parseJSDocCommentWorker

Function parseJSDocCommentWorker

test/fixtures/snapshot/typescript.js:37470–38336  ·  view source on GitHub ↗
(start, length)

Source from the content-addressed store, hash-verified

37468 PropertyLikeParse[PropertyLikeParse["CallbackParameter"] = 4] = "CallbackParameter";
37469 })(PropertyLikeParse || (PropertyLikeParse = {}));
37470 function parseJSDocCommentWorker(start, length) {
37471 if (start === void 0) { start = 0; }
37472 var content = sourceText;
37473 var end = length === undefined ? content.length : start + length;
37474 length = end - start;
37475 ts.Debug.assert(start >= 0);
37476 ts.Debug.assert(start <= end);
37477 ts.Debug.assert(end <= content.length);
37478 // Check for /** (JSDoc opening part)
37479 if (!isJSDocLikeText(content, start)) {
37480 return undefined;
37481 }
37482 var tags;
37483 var tagsPos;
37484 var tagsEnd;
37485 var linkEnd;
37486 var commentsPos;
37487 var comments = [];
37488 var parts = [];
37489 // + 3 for leading /**, - 5 in total for /** */
37490 return scanner.scanRange(start + 3, length - 5, function () {
37491 // Initially we can parse out a tag. We also have seen a starting asterisk.
37492 // This is so that /** * @type */ doesn't parse.
37493 var state = 1 /* JSDocState.SawAsterisk */;
37494 var margin;
37495 // + 4 for leading '/** '
37496 // + 1 because the last index of \n is always one index before the first character in the line and coincidentally, if there is no \n before start, it is -1, which is also one index before the first character
37497 var indent = start - (content.lastIndexOf("\n", start) + 1) + 4;
37498 function pushComment(text) {
37499 if (!margin) {
37500 margin = indent;
37501 }
37502 comments.push(text);
37503 indent += text.length;
37504 }
37505 nextTokenJSDoc();
37506 while (parseOptionalJsdoc(5 /* SyntaxKind.WhitespaceTrivia */))
37507 ;
37508 if (parseOptionalJsdoc(4 /* SyntaxKind.NewLineTrivia */)) {
37509 state = 0 /* JSDocState.BeginningOfLine */;
37510 indent = 0;
37511 }
37512 loop: while (true) {
37513 switch (token()) {
37514 case 59 /* SyntaxKind.AtToken */:
37515 if (state === 0 /* JSDocState.BeginningOfLine */ || state === 1 /* JSDocState.SawAsterisk */) {
37516 removeTrailingWhitespace(comments);
37517 if (!commentsPos)
37518 commentsPos = getNodePos();
37519 addTag(parseTag(indent));
37520 // NOTE: According to usejsdoc.org, a tag goes to end of line, except the last tag.
37521 // Real-world comments may break this rule, so "BeginningOfLine" will not be a real line beginning
37522 // for malformed examples like `/** @param {string} x @returns {number} the length */`
37523 state = 0 /* JSDocState.BeginningOfLine */;
37524 margin = undefined;
37525 }
37526 else {
37527 pushComment(scanner.getTokenText());

Callers 2

parseJSDocCommentFunction · 0.85

Calls 15

isJSDocLikeTextFunction · 0.85
nextTokenJSDocFunction · 0.85
parseOptionalJsdocFunction · 0.85
removeTrailingWhitespaceFunction · 0.85
getNodePosFunction · 0.85
addTagFunction · 0.85
parseTagFunction · 0.85
pushCommentFunction · 0.85
parseJSDocLinkFunction · 0.85
removeLeadingNewlinesFunction · 0.85
finishNodeFunction · 0.85
createNodeArrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…