Include code fix after prologue

Fixes #15515
This commit is contained in:
Sheetal Nandi
2018-11-09 16:02:16 -08:00
parent 50a0174582
commit c60ff902f1
2 changed files with 64 additions and 2 deletions

View File

@@ -1005,9 +1005,26 @@ namespace ts.textChanges {
}
}
function getInsertionPositionAtSourceFileTop({ text }: SourceFile): number {
const shebang = getShebang(text);
function getInsertionPositionAtSourceFileTop(sourceFile: SourceFile): number {
let lastPrologue: PrologueDirective | undefined;
for (const node of sourceFile.statements) {
if (isPrologueDirective(node)) {
lastPrologue = node;
}
else {
break;
}
}
let position = 0;
const text = sourceFile.text;
if (lastPrologue) {
position = lastPrologue.end;
advancePastLineBreak();
return position;
}
const shebang = getShebang(text);
if (shebang !== undefined) {
position = shebang.length;
advancePastLineBreak();