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

Function indentMultilineComment

test/fixtures/snapshot/typescript.js:147775–147822  ·  view source on GitHub ↗
(commentRange, indentation, firstLineIsIndented, indentFinalLine)

Source from the content-addressed store, hash-verified

147773 return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
147774 }
147775 function indentMultilineComment(commentRange, indentation, firstLineIsIndented, indentFinalLine) {
147776 if (indentFinalLine === void 0) { indentFinalLine = true; }
147777 // split comment in lines
147778 var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
147779 var endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line;
147780 if (startLine === endLine) {
147781 if (!firstLineIsIndented) {
147782 // treat as single line comment
147783 insertIndentation(commentRange.pos, indentation, /*lineAdded*/ false);
147784 }
147785 return;
147786 }
147787 var parts = [];
147788 var startPos = commentRange.pos;
147789 for (var line = startLine; line < endLine; line++) {
147790 var endOfLine = ts.getEndLinePosition(line, sourceFile);
147791 parts.push({ pos: startPos, end: endOfLine });
147792 startPos = ts.getStartPositionOfLine(line + 1, sourceFile);
147793 }
147794 if (indentFinalLine) {
147795 parts.push({ pos: startPos, end: commentRange.end });
147796 }
147797 if (parts.length === 0)
147798 return;
147799 var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile);
147800 var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options);
147801 var startIndex = 0;
147802 if (firstLineIsIndented) {
147803 startIndex = 1;
147804 startLine++;
147805 }
147806 // shift all parts on the delta size
147807 var delta = indentation - nonWhitespaceColumnInFirstPart.column;
147808 for (var i = startIndex; i < parts.length; i++, startLine++) {
147809 var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile);
147810 var nonWhitespaceCharacterAndColumn = i === 0
147811 ? nonWhitespaceColumnInFirstPart
147812 : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options);
147813 var newIndentation = nonWhitespaceCharacterAndColumn.column + delta;
147814 if (newIndentation > 0) {
147815 var indentationString = getIndentationString(newIndentation, options);
147816 recordReplace(startLinePos_1, nonWhitespaceCharacterAndColumn.character, indentationString);
147817 }
147818 else {
147819 recordDelete(startLinePos_1, nonWhitespaceCharacterAndColumn.character);
147820 }
147821 }
147822 }
147823 function trimTrailingWhitespacesForLines(line1, line2, range) {
147824 for (var line = line1; line < line2; line++) {
147825 var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile);

Callers 1

indentTriviaItemsFunction · 0.85

Calls 5

insertIndentationFunction · 0.85
getIndentationStringFunction · 0.85
recordReplaceFunction · 0.85
recordDeleteFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected