Skip to content

useNonAdjustedEndPosition when replacing import node #22517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/codefixes/useDefaultImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ namespace ts.codefix {
}

function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, info: Info): void {
changes.replaceNode(sourceFile, info.importNode, makeImportDeclaration(info.name, /*namedImports*/ undefined, info.moduleSpecifier));
changes.replaceNode(sourceFile, info.importNode, makeImportDeclaration(info.name, /*namedImports*/ undefined, info.moduleSpecifier), textChanges.useNonAdjustedPositions);
}
}
6 changes: 3 additions & 3 deletions tests/cases/fourslash/codeFixUseDefaultImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
////export = x;

// @Filename: /b.ts
////import * as [|a|] from "./a";
/////*com ment*/import * as [|a|] from "./a";/*tnem moc*/

// @Filename: /c.ts
////import [|a|] = require("./a");
/////*com ment*/import [|a|] = require("./a");/*tnem moc*/

// @Filename: /d.ts
////import "./a";
Expand All @@ -29,7 +29,7 @@ for (const file of ["/b.ts", "/c.ts"]) {

verify.codeFix({
description: "Convert to default import",
newFileContent: `import a from "./a";`,
newFileContent: `/*com ment*/import a from "./a";/*tnem moc*/`,
});
}

Expand Down
5 changes: 3 additions & 2 deletions tests/cases/fourslash/codeFixUseDefaultImport_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
goTo.file("/b.ts");
verify.codeFixAll({
fixId: "useDefaultImport",
// TODO: GH#22337
newFileContent: `import a1 from "./a";import a2 from "./a";`,
newFileContent:
`import a1 from "./a";
import a2 from "./a";`,
});