mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 02:30:15 -06:00
importFixes: Fix bug by using replaceNode and removing changeIdentifierToPropertyAccess (#21898)
This commit is contained in:
parent
20a6be67a0
commit
458c12fa78
@ -637,7 +637,7 @@ namespace ts.codefix {
|
||||
* become "ns.foo"
|
||||
*/
|
||||
const changes = ChangeTracker.with(context, tracker =>
|
||||
tracker.changeIdentifierToPropertyAccess(sourceFile, namespacePrefix, symbolToken));
|
||||
tracker.replaceNode(sourceFile, symbolToken, createPropertyAccess(createIdentifier(namespacePrefix), symbolToken)));
|
||||
return createCodeAction(Diagnostics.Change_0_to_1, [symbolName, `${namespacePrefix}.${symbolName}`], changes);
|
||||
}
|
||||
|
||||
|
||||
@ -344,11 +344,6 @@ namespace ts.textChanges {
|
||||
this.replaceRange(sourceFile, { pos, end: pos }, createToken(modifier), { suffix: " " });
|
||||
}
|
||||
|
||||
public changeIdentifierToPropertyAccess(sourceFile: SourceFile, prefix: string, node: Identifier): void {
|
||||
const pos = getAdjustedStartPosition(sourceFile, node, {}, Position.Start);
|
||||
this.replaceRange(sourceFile, { pos, end: pos }, createPropertyAccess(createIdentifier(prefix), ""), {});
|
||||
}
|
||||
|
||||
private getOptionsForInsertNodeBefore(before: Node, doubleNewlines: boolean): ChangeNodeOptions {
|
||||
if (isStatement(before) || isClassElement(before)) {
|
||||
return { suffix: doubleNewlines ? this.newLineCharacter + this.newLineCharacter : this.newLineCharacter };
|
||||
|
||||
22
tests/cases/fourslash/importNameCodeFixIndentedIdentifier.ts
Normal file
22
tests/cases/fourslash/importNameCodeFixIndentedIdentifier.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////[|import * as b from "./b";
|
||||
////{
|
||||
//// x/**/
|
||||
////}|]
|
||||
|
||||
// @Filename: /b.ts
|
||||
////export const x = 0;
|
||||
|
||||
verify.importFixAtPosition([
|
||||
`import * as b from "./b";
|
||||
{
|
||||
b.x
|
||||
}`,
|
||||
`import * as b from "./b";
|
||||
import { x } from "./b";
|
||||
{
|
||||
x
|
||||
}`,
|
||||
]);
|
||||
Loading…
x
Reference in New Issue
Block a user