// TODO: avoid pre-computing line starts, can tss use SourceFiles instead? /* @internal, from scanner.ts */ function computeLineStarts(text) { var result = new Array(); var pos = 0; var lineStart = 0; while (pos < text.length) { var ch = text.charCodeAt(pos++); switch (ch) { case 0x0D: if (text.charCodeAt(pos) === 0x0A) { pos++; } case 0x0A: result.push(lineStart); lineStart = pos; break; default: if (ch > 0x7F && ts.isLineBreak(ch)) { result.push(lineStart); lineStart = pos; } break; } } result.push(lineStart); return result; }
/** * Calculates the index after the newline following pos, or the beginning of the next token, whichever comes first. * See also getSplitIndexes. * This method is a modified version of TypeScript's internal iterateCommentRanges function. */ function getNextSplitIndex(text, pos) { scan: while (pos >= 0 && pos < text.length) { var ch = text.charCodeAt(pos); switch (ch) { case 13 /* carriageReturn */: if (text.charCodeAt(pos + 1) === 10 /* lineFeed */) { pos++; } // falls through case 10 /* lineFeed */: pos++; // split is after new line return pos; case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: // skip whitespace pos++; continue; case 47 /* slash */: var nextChar = text.charCodeAt(pos + 1); if (nextChar === 47 /* slash */ || nextChar === 42 /* asterisk */) { var isSingleLineComment = nextChar === 47 /* slash */; pos += 2; if (isSingleLineComment) { while (pos < text.length) { if (ts.isLineBreak(text.charCodeAt(pos))) { // the comment ends here, go back to default logic to handle parsing new line and result continue scan; } pos++; } } else { while (pos < text.length) { if (text.charCodeAt(pos) === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; continue scan; } pos++; } } // if we arrive here, it's because pos == text.length return pos; } break scan; default: // skip whitespace: if (ch > 127 /* maxAsciiCharacter */ && (ts.isWhiteSpaceLike(ch))) { pos++; continue; } break scan; } } return pos; }
TypedefWhitespaceWalker.prototype.checkLeft = function (colonStart, option, key) { var pos = colonStart; var text = this.sourceFile.text; var current = text.charCodeAt(pos - 1); while (ts.isWhiteSpaceSingleLine(current)) { --pos; current = text.charCodeAt(pos - 1); } if (ts.isLineBreak(current)) { return; } return this.validateWhitespace(pos, colonStart, option, "before", key); };
TypedefWhitespaceWalker.prototype.checkRight = function (colonEnd, option, key) { var pos = colonEnd; var text = this.sourceFile.text; var current = text.charCodeAt(pos); if (ts.isLineBreak(current)) { return; } while (ts.isWhiteSpaceSingleLine(current)) { ++pos; current = text.charCodeAt(pos); } return this.validateWhitespace(colonEnd, pos, option, "after", key); };