Ensure that the comma is removed when all named imports are removed via moveToFile - fixes #31195

This commit is contained in:
Orta Therox 2019-08-01 14:08:58 -04:00
parent b377e99958
commit c337f046fb
3 changed files with 33 additions and 2 deletions

View File

@ -2430,7 +2430,7 @@ namespace FourSlash {
const oldText = this.tryGetFileContent(change.fileName);
ts.Debug.assert(!!change.isNewFile === (oldText === undefined));
const newContent = change.isNewFile ? ts.first(change.textChanges).newText : ts.textChanges.applyChanges(oldText!, change.textChanges);
assert.equal(newContent, expectedNewContent);
assert.equal(newContent, expectedNewContent, `String mis-matched in file ${change.fileName}`);
}
for (const newFileName in newFileContent) {
ts.Debug.assert(changes.some(c => c.fileName === newFileName), "No change in file", () => newFileName);

View File

@ -350,7 +350,11 @@ namespace ts.refactor {
}
if (namedBindings) {
if (namedBindingsUnused) {
changes.delete(sourceFile, namedBindings);
changes.replaceNode(
sourceFile,
importDecl.importClause,
updateImportClause(importDecl.importClause, name, /*namedBindings*/ undefined)
);
}
else if (namedBindings.kind === SyntaxKind.NamedImports) {
for (const element of namedBindings.elements) {

View File

@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />
// @Filename: /has-exports.ts
////
//// export interface Exported { }
//// const defaultExport = ""
//// export default defaultExport
// @Filename: /31195.ts
////
////import defaultExport, { Exported } from "./has-exports"
////console.log(defaultExport)
////[|export const bar = (logger: Exported) => 0;|]
verify.moveToNewFile({
newFileContents: {
"/31195.ts": `
import defaultExport from "./has-exports"
console.log(defaultExport)
`,
"/bar.ts":
`import { Exported } from "./has-exports";
export const bar = (logger: Exported) => 0;
`,
}
});