mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Merge pull request #19791 from amcasey/ImportLineBreaks
Handle windows linebreaks in getSourceFileImportLocation
This commit is contained in:
@@ -1330,23 +1330,39 @@ namespace ts {
|
||||
export function getSourceFileImportLocation(node: SourceFile) {
|
||||
// For a source file, it is possible there are detached comments we should not skip
|
||||
const text = node.text;
|
||||
const textLength = text.length;
|
||||
let ranges = getLeadingCommentRanges(text, 0);
|
||||
if (!ranges) return 0;
|
||||
let position = 0;
|
||||
// However we should still skip a pinned comment at the top
|
||||
if (ranges.length && ranges[0].kind === SyntaxKind.MultiLineCommentTrivia && isPinnedComment(text, ranges[0])) {
|
||||
position = ranges[0].end + 1;
|
||||
position = ranges[0].end;
|
||||
advancePastLineBreak();
|
||||
ranges = ranges.slice(1);
|
||||
}
|
||||
// As well as any triple slash references
|
||||
for (const range of ranges) {
|
||||
if (range.kind === SyntaxKind.SingleLineCommentTrivia && isRecognizedTripleSlashComment(node.text, range.pos, range.end)) {
|
||||
position = range.end + 1;
|
||||
position = range.end;
|
||||
advancePastLineBreak();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return position;
|
||||
|
||||
function advancePastLineBreak() {
|
||||
if (position < textLength) {
|
||||
const charCode = text.charCodeAt(position);
|
||||
if (isLineBreak(charCode)) {
|
||||
position++;
|
||||
|
||||
if (position < textLength && charCode === CharacterCodes.carriageReturn && text.charCodeAt(position) === CharacterCodes.lineFeed) {
|
||||
position++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user