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

Function getEncodedSyntacticClassifications

test/fixtures/snapshot/typescript.js:130507–130944  ·  view source on GitHub ↗
(cancellationToken, sourceFile, span)

Source from the content-addressed store, hash-verified

130505 ts.getSyntacticClassifications = getSyntacticClassifications;
130506 /* @internal */
130507 function getEncodedSyntacticClassifications(cancellationToken, sourceFile, span) {
130508 var spanStart = span.start;
130509 var spanLength = span.length;
130510 // Make a scanner we can get trivia from.
130511 var triviaScanner = ts.createScanner(99 /* ScriptTarget.Latest */, /*skipTrivia*/ false, sourceFile.languageVariant, sourceFile.text);
130512 var mergeConflictScanner = ts.createScanner(99 /* ScriptTarget.Latest */, /*skipTrivia*/ false, sourceFile.languageVariant, sourceFile.text);
130513 var result = [];
130514 processElement(sourceFile);
130515 return { spans: result, endOfLineState: 0 /* EndOfLineState.None */ };
130516 function pushClassification(start, length, type) {
130517 result.push(start);
130518 result.push(length);
130519 result.push(type);
130520 }
130521 function classifyLeadingTriviaAndGetTokenStart(token) {
130522 triviaScanner.setTextPos(token.pos);
130523 while (true) {
130524 var start = triviaScanner.getTextPos();
130525 // only bother scanning if we have something that could be trivia.
130526 if (!ts.couldStartTrivia(sourceFile.text, start)) {
130527 return start;
130528 }
130529 var kind = triviaScanner.scan();
130530 var end = triviaScanner.getTextPos();
130531 var width = end - start;
130532 // The moment we get something that isn't trivia, then stop processing.
130533 if (!ts.isTrivia(kind)) {
130534 return start;
130535 }
130536 switch (kind) {
130537 case 4 /* SyntaxKind.NewLineTrivia */:
130538 case 5 /* SyntaxKind.WhitespaceTrivia */:
130539 // Don't bother with newlines/whitespace.
130540 continue;
130541 case 2 /* SyntaxKind.SingleLineCommentTrivia */:
130542 case 3 /* SyntaxKind.MultiLineCommentTrivia */:
130543 // Only bother with the trivia if it at least intersects the span of interest.
130544 classifyComment(token, kind, start, width);
130545 // Classifying a comment might cause us to reuse the trivia scanner
130546 // (because of jsdoc comments). So after we classify the comment make
130547 // sure we set the scanner position back to where it needs to be.
130548 triviaScanner.setTextPos(end);
130549 continue;
130550 case 7 /* SyntaxKind.ConflictMarkerTrivia */:
130551 var text = sourceFile.text;
130552 var ch = text.charCodeAt(start);
130553 // for the <<<<<<< and >>>>>>> markers, we just add them in as comments
130554 // in the classification stream.
130555 if (ch === 60 /* CharacterCodes.lessThan */ || ch === 62 /* CharacterCodes.greaterThan */) {
130556 pushClassification(start, width, 1 /* ClassificationType.comment */);
130557 continue;
130558 }
130559 // for the ||||||| and ======== markers, add a comment for the first line,
130560 // and then lex all subsequent lines up until the end of the conflict marker.
130561 ts.Debug.assert(ch === 124 /* CharacterCodes.bar */ || ch === 61 /* CharacterCodes.equals */);
130562 classifyDisabledMergeCode(text, start, end);
130563 break;
130564 case 6 /* SyntaxKind.ShebangTrivia */:

Callers 1

Calls 1

processElementFunction · 0.85

Tested by

no test coverage detected