MCPcopy Create free account
hub / github.com/nodejs/node / markPrecedingCommentDirectiveLine

Function markPrecedingCommentDirectiveLine

test/fixtures/snapshot/typescript.js:117684–117705  ·  view source on GitHub ↗

* @returns The line index marked as preceding the diagnostic, or -1 if none was.

(diagnostic, directives)

Source from the content-addressed store, hash-verified

117682 * @returns The line index marked as preceding the diagnostic, or -1 if none was.
117683 */
117684 function markPrecedingCommentDirectiveLine(diagnostic, directives) {
117685 var file = diagnostic.file, start = diagnostic.start;
117686 if (!file) {
117687 return -1;
117688 }
117689 // Start out with the line just before the text
117690 var lineStarts = ts.getLineStarts(file);
117691 var line = ts.computeLineAndCharacterOfPosition(lineStarts, start).line - 1; // TODO: GH#18217
117692 while (line >= 0) {
117693 // As soon as that line is known to have a comment directive, use that
117694 if (directives.markUsed(line)) {
117695 return line;
117696 }
117697 // Stop searching if the line is not empty and not a comment
117698 var lineText = file.text.slice(lineStarts[line], lineStarts[line + 1]).trim();
117699 if (lineText !== "" && !/^(\s*)\/\/(.*)$/.test(lineText)) {
117700 return -1;
117701 }
117702 line--;
117703 }
117704 return -1;
117705 }
117706 function getJSSyntacticDiagnosticsForFile(sourceFile) {
117707 return runWithCancellationToken(function () {
117708 var diagnostics = [];

Callers 1

Calls 2

sliceMethod · 0.65
testMethod · 0.45

Tested by

no test coverage detected