Handle other linebreak characters and add boundary checks
This commit is contained in:
parent
d1fa006a1e
commit
3e339d88a1
1 changed files with 9 additions and 5 deletions
|
@ -1330,6 +1330,7 @@ namespace ts {
|
||||||
export function getSourceFileImportLocation(node: SourceFile) {
|
export function getSourceFileImportLocation(node: SourceFile) {
|
||||||
// For a source file, it is possible there are detached comments we should not skip
|
// For a source file, it is possible there are detached comments we should not skip
|
||||||
const text = node.text;
|
const text = node.text;
|
||||||
|
const textLength = text.length;
|
||||||
let ranges = getLeadingCommentRanges(text, 0);
|
let ranges = getLeadingCommentRanges(text, 0);
|
||||||
if (!ranges) return 0;
|
if (!ranges) return 0;
|
||||||
let position = 0;
|
let position = 0;
|
||||||
|
@ -1351,12 +1352,15 @@ namespace ts {
|
||||||
return position;
|
return position;
|
||||||
|
|
||||||
function AdvancePastLineBreak() {
|
function AdvancePastLineBreak() {
|
||||||
if (text.charCodeAt(position) === CharacterCodes.carriageReturn) {
|
if (position < textLength) {
|
||||||
position++;
|
const charCode = text.charCodeAt(position);
|
||||||
}
|
if (isLineBreak(charCode)) {
|
||||||
|
position++;
|
||||||
|
|
||||||
if (text.charCodeAt(position) === CharacterCodes.lineFeed) {
|
if (position < textLength && charCode === CharacterCodes.carriageReturn && text.charCodeAt(position) === CharacterCodes.lineFeed) {
|
||||||
position++;
|
position++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue