mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 06:02:53 -05:00
@@ -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 { }`,
|
||||
});
|
||||
Reference in New Issue
Block a user