Skip to content
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
7 changes: 5 additions & 2 deletions src/services/codefixes/importFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,12 @@ namespace ts.codefix {
const aliased = checker.getImmediateAliasedSymbol(defaultExport);
return aliased && getDefaultExportInfoWorker(aliased, Debug.assertDefined(aliased.parent), checker, compilerOptions);
}
else {
return { symbolForMeaning: defaultExport, name: moduleSymbolToValidIdentifier(moduleSymbol, compilerOptions.target!) };

if (defaultExport.escapedName !== InternalSymbolName.Default &&
defaultExport.escapedName !== InternalSymbolName.ExportEquals) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also check that that name isIdentifierText, just in case the name comes from, say, a jsdoc typedef or a js property assignment where the original declaration's name wasn't an identifier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weswigham we don't need to check that since this is the name just to compare the defaultExportSymbol ==== symbol we are looking for and that symbol's name does default to symbol.name if its not export= or default. The actual text to be displayed is calculated later.

return { symbolForMeaning: defaultExport, name: defaultExport.getName() };
}
return { symbolForMeaning: defaultExport, name: moduleSymbolToValidIdentifier(moduleSymbol, compilerOptions.target!) };
}

function getNameForExportDefault(symbol: Symbol): string | undefined {
Expand Down
44 changes: 44 additions & 0 deletions tests/cases/fourslash/completionsImport_default_symbolName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/// <reference path="fourslash.ts" />

// @module: commonjs

// @Filename: /node_modules/@types/range-parser/index.d.ts
////declare function RangeParser(): string;
////declare namespace RangeParser {
//// interface Options {
//// combine?: boolean;
//// }
////}
////export = RangeParser;

// @Filename: /b.ts
////R/*0*/

verify.completions(
{
marker: "0",
includes: {
name: "RangeParser",
kind: "function",
kindModifiers: "declare",
source: "/node_modules/@types/range-parser/index",
sourceDisplay: "range-parser",
hasAction: true,
sortText: completion.SortText.AutoImportSuggestions,
text: `namespace RangeParser
function RangeParser(): string`
},
preferences: {
includeCompletionsForModuleExports: true
}
},
);

verify.applyCodeActionFromCompletion("0", {
name: "RangeParser",
source: "/node_modules/@types/range-parser/index",
description: `Import 'RangeParser' from module "range-parser"`,
newFileContent: `import RangeParser = require("range-parser");

R`,
});