Skip to content

Commit 62eeb72

Browse files
authored
Merge pull request microsoft#19791 from amcasey/ImportLineBreaks
Handle windows linebreaks in getSourceFileImportLocation
2 parents fe40873 + 2715f89 commit 62eeb72

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/services/utilities.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,23 +1330,39 @@ 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;
13361337
// However we should still skip a pinned comment at the top
13371338
if (ranges.length && ranges[0].kind === SyntaxKind.MultiLineCommentTrivia && isPinnedComment(text, ranges[0])) {
1338-
position = ranges[0].end + 1;
1339+
position = ranges[0].end;
1340+
advancePastLineBreak();
13391341
ranges = ranges.slice(1);
13401342
}
13411343
// As well as any triple slash references
13421344
for (const range of ranges) {
13431345
if (range.kind === SyntaxKind.SingleLineCommentTrivia && isRecognizedTripleSlashComment(node.text, range.pos, range.end)) {
1344-
position = range.end + 1;
1346+
position = range.end;
1347+
advancePastLineBreak();
13451348
continue;
13461349
}
13471350
break;
13481351
}
13491352
return position;
1353+
1354+
function advancePastLineBreak() {
1355+
if (position < textLength) {
1356+
const charCode = text.charCodeAt(position);
1357+
if (isLineBreak(charCode)) {
1358+
position++;
1359+
1360+
if (position < textLength && charCode === CharacterCodes.carriageReturn && text.charCodeAt(position) === CharacterCodes.lineFeed) {
1361+
position++;
1362+
}
1363+
}
1364+
}
1365+
}
13501366
}
13511367

13521368
/**

0 commit comments

Comments
 (0)