Skip to content

Commit 458c12f

Browse files
author
Andy
authored
importFixes: Fix bug by using replaceNode and removing changeIdentifierToPropertyAccess (microsoft#21898)
1 parent 20a6be6 commit 458c12f

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ namespace ts.codefix {
637637
* become "ns.foo"
638638
*/
639639
const changes = ChangeTracker.with(context, tracker =>
640-
tracker.changeIdentifierToPropertyAccess(sourceFile, namespacePrefix, symbolToken));
640+
tracker.replaceNode(sourceFile, symbolToken, createPropertyAccess(createIdentifier(namespacePrefix), symbolToken)));
641641
return createCodeAction(Diagnostics.Change_0_to_1, [symbolName, `${namespacePrefix}.${symbolName}`], changes);
642642
}
643643

src/services/textChanges.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,6 @@ namespace ts.textChanges {
344344
this.replaceRange(sourceFile, { pos, end: pos }, createToken(modifier), { suffix: " " });
345345
}
346346

347-
public changeIdentifierToPropertyAccess(sourceFile: SourceFile, prefix: string, node: Identifier): void {
348-
const pos = getAdjustedStartPosition(sourceFile, node, {}, Position.Start);
349-
this.replaceRange(sourceFile, { pos, end: pos }, createPropertyAccess(createIdentifier(prefix), ""), {});
350-
}
351-
352347
private getOptionsForInsertNodeBefore(before: Node, doubleNewlines: boolean): ChangeNodeOptions {
353348
if (isStatement(before) || isClassElement(before)) {
354349
return { suffix: doubleNewlines ? this.newLineCharacter + this.newLineCharacter : this.newLineCharacter };
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /a.ts
4+
////[|import * as b from "./b";
5+
////{
6+
//// x/**/
7+
////}|]
8+
9+
// @Filename: /b.ts
10+
////export const x = 0;
11+
12+
verify.importFixAtPosition([
13+
`import * as b from "./b";
14+
{
15+
b.x
16+
}`,
17+
`import * as b from "./b";
18+
import { x } from "./b";
19+
{
20+
x
21+
}`,
22+
]);

0 commit comments

Comments
 (0)