Merge pull request #28454 from Microsoft/codeFixAfterPrologue
Include code fix after prologue
This commit is contained in:
commit
d6df82a77c
2 changed files with 64 additions and 2 deletions
|
@ -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();
|
||||
|
|
45
tests/cases/fourslash/importNameCodeFixWithPrologue.ts
Normal file
45
tests/cases/fourslash/importNameCodeFixWithPrologue.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////"use strict";
|
||||
////export class A { }
|
||||
|
||||
// @Filename: /b.ts
|
||||
////"use strict";
|
||||
////export class B extends A { }
|
||||
|
||||
// @Filename: /c.ts
|
||||
/////*---------------------------------------------------------------------------------------------
|
||||
//// * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//// * Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
//// *--------------------------------------------------------------------------------------------*/
|
||||
////"use strict";
|
||||
////export class B extends A { }
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.codeFixAll({
|
||||
fixId: "fixMissingImport",
|
||||
fixAllDescription: "Add all missing imports",
|
||||
newFileContent:
|
||||
`"use strict";
|
||||
|
||||
import { A } from "./a";
|
||||
|
||||
export class B extends A { }`,
|
||||
});
|
||||
|
||||
goTo.file("/c.ts");
|
||||
verify.codeFixAll({
|
||||
fixId: "fixMissingImport",
|
||||
fixAllDescription: "Add all missing imports",
|
||||
newFileContent:
|
||||
`/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
"use strict";
|
||||
|
||||
import { A } from "./a";
|
||||
|
||||
export class B extends A { }`,
|
||||
});
|
Loading…
Reference in a new issue