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

Function tryClassifyTripleSlashComment

test/fixtures/snapshot/typescript.js:130684–130748  ·  view source on GitHub ↗
(start, width)

Source from the content-addressed store, hash-verified

130682 }
130683 }
130684 function tryClassifyTripleSlashComment(start, width) {
130685 var tripleSlashXMLCommentRegEx = /^(\/\/\/\s*)(<)(?:(\S+)((?:[^/]|\/[^>])*)(\/>)?)?/im;
130686 // Require a leading whitespace character (the parser already does) to prevent terrible backtracking performance
130687 var attributeRegex = /(\s)(\S+)(\s*)(=)(\s*)('[^']+'|"[^"]+")/img;
130688 var text = sourceFile.text.substr(start, width);
130689 var match = tripleSlashXMLCommentRegEx.exec(text);
130690 if (!match) {
130691 return false;
130692 }
130693 // Limiting classification to exactly the elements and attributes
130694 // defined in `ts.commentPragmas` would be excessive, but we can avoid
130695 // some obvious false positives (e.g. in XML-like doc comments) by
130696 // checking the element name.
130697 // eslint-disable-next-line no-in-operator
130698 if (!match[3] || !(match[3] in ts.commentPragmas)) {
130699 return false;
130700 }
130701 var pos = start;
130702 pushCommentRange(pos, match[1].length); // ///
130703 pos += match[1].length;
130704 pushClassification(pos, match[2].length, 10 /* ClassificationType.punctuation */); // <
130705 pos += match[2].length;
130706 pushClassification(pos, match[3].length, 21 /* ClassificationType.jsxSelfClosingTagName */); // element name
130707 pos += match[3].length;
130708 var attrText = match[4];
130709 var attrPos = pos;
130710 while (true) {
130711 var attrMatch = attributeRegex.exec(attrText);
130712 if (!attrMatch) {
130713 break;
130714 }
130715 var newAttrPos = pos + attrMatch.index + attrMatch[1].length; // whitespace
130716 if (newAttrPos > attrPos) {
130717 pushCommentRange(attrPos, newAttrPos - attrPos);
130718 attrPos = newAttrPos;
130719 }
130720 pushClassification(attrPos, attrMatch[2].length, 22 /* ClassificationType.jsxAttribute */); // attribute name
130721 attrPos += attrMatch[2].length;
130722 if (attrMatch[3].length) {
130723 pushCommentRange(attrPos, attrMatch[3].length); // whitespace
130724 attrPos += attrMatch[3].length;
130725 }
130726 pushClassification(attrPos, attrMatch[4].length, 5 /* ClassificationType.operator */); // =
130727 attrPos += attrMatch[4].length;
130728 if (attrMatch[5].length) {
130729 pushCommentRange(attrPos, attrMatch[5].length); // whitespace
130730 attrPos += attrMatch[5].length;
130731 }
130732 pushClassification(attrPos, attrMatch[6].length, 24 /* ClassificationType.jsxAttributeStringLiteralValue */); // attribute value
130733 attrPos += attrMatch[6].length;
130734 }
130735 pos += match[4].length;
130736 if (pos > attrPos) {
130737 pushCommentRange(attrPos, pos - attrPos);
130738 }
130739 if (match[5]) {
130740 pushClassification(pos, match[5].length, 10 /* ClassificationType.punctuation */); // />
130741 pos += match[5].length;

Callers 1

classifyCommentFunction · 0.85

Calls 3

pushCommentRangeFunction · 0.85
pushClassificationFunction · 0.85
execMethod · 0.45

Tested by

no test coverage detected