Skip to content

Commit c60ff90

Browse files
committed
Include code fix after prologue
Fixes #15515
1 parent 50a0174 commit c60ff90

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/services/textChanges.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,26 @@ namespace ts.textChanges {
10051005
}
10061006
}
10071007

1008-
function getInsertionPositionAtSourceFileTop({ text }: SourceFile): number {
1009-
const shebang = getShebang(text);
1008+
function getInsertionPositionAtSourceFileTop(sourceFile: SourceFile): number {
1009+
let lastPrologue: PrologueDirective | undefined;
1010+
for (const node of sourceFile.statements) {
1011+
if (isPrologueDirective(node)) {
1012+
lastPrologue = node;
1013+
}
1014+
else {
1015+
break;
1016+
}
1017+
}
1018+
10101019
let position = 0;
1020+
const text = sourceFile.text;
1021+
if (lastPrologue) {
1022+
position = lastPrologue.end;
1023+
advancePastLineBreak();
1024+
return position;
1025+
}
1026+
1027+
const shebang = getShebang(text);
10111028
if (shebang !== undefined) {
10121029
position = shebang.length;
10131030
advancePastLineBreak();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /a.ts
4+
////"use strict";
5+
////export class A { }
6+
7+
// @Filename: /b.ts
8+
////"use strict";
9+
////export class B extends A { }
10+
11+
// @Filename: /c.ts
12+
/////*---------------------------------------------------------------------------------------------
13+
//// * Copyright (c) Microsoft Corporation. All rights reserved.
14+
//// * Licensed under the MIT License. See License.txt in the project root for license information.
15+
//// *--------------------------------------------------------------------------------------------*/
16+
////"use strict";
17+
////export class B extends A { }
18+
19+
goTo.file("/b.ts");
20+
verify.codeFixAll({
21+
fixId: "fixMissingImport",
22+
fixAllDescription: "Add all missing imports",
23+
newFileContent:
24+
`"use strict";
25+
26+
import { A } from "./a";
27+
28+
export class B extends A { }`,
29+
});
30+
31+
goTo.file("/c.ts");
32+
verify.codeFixAll({
33+
fixId: "fixMissingImport",
34+
fixAllDescription: "Add all missing imports",
35+
newFileContent:
36+
`/*---------------------------------------------------------------------------------------------
37+
* Copyright (c) Microsoft Corporation. All rights reserved.
38+
* Licensed under the MIT License. See License.txt in the project root for license information.
39+
*--------------------------------------------------------------------------------------------*/
40+
"use strict";
41+
42+
import { A } from "./a";
43+
44+
export class B extends A { }`,
45+
});

0 commit comments

Comments
 (0)