Merge pull request #28454 from Microsoft/codeFixAfterPrologue

Include code fix after prologue
This commit is contained in:
Sheetal Nandi 2018-11-09 16:56:43 -08:00 committed by GitHub
commit d6df82a77c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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();

View 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 { }`,
});