Skip to content

Commit 3e339d8

Browse files
committed
Handle other linebreak characters and add boundary checks
1 parent d1fa006 commit 3e339d8

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/services/utilities.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ namespace ts {
13301330
export function getSourceFileImportLocation(node: SourceFile) {
13311331
// For a source file, it is possible there are detached comments we should not skip
13321332
const text = node.text;
1333+
const textLength = text.length;
13331334
let ranges = getLeadingCommentRanges(text, 0);
13341335
if (!ranges) return 0;
13351336
let position = 0;
@@ -1351,12 +1352,15 @@ namespace ts {
13511352
return position;
13521353

13531354
function AdvancePastLineBreak() {
1354-
if (text.charCodeAt(position) === CharacterCodes.carriageReturn) {
1355-
position++;
1356-
}
1355+
if (position < textLength) {
1356+
const charCode = text.charCodeAt(position);
1357+
if (isLineBreak(charCode)) {
1358+
position++;
13571359

1358-
if (text.charCodeAt(position) === CharacterCodes.lineFeed) {
1359-
position++;
1360+
if (position < textLength && charCode === CharacterCodes.carriageReturn && text.charCodeAt(position) === CharacterCodes.lineFeed) {
1361+
position++;
1362+
}
1363+
}
13601364
}
13611365
}
13621366
}

0 commit comments

Comments
 (0)