diff --git a/src/services/completions.ts b/src/services/completions.ts index 8203b66549b..f17ee862cca 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -367,7 +367,9 @@ namespace ts.Completions { } function getSymbolName(symbol: Symbol, origin: SymbolOriginInfo | undefined, target: ScriptTarget): string { - return origin && originIsExport(origin) && origin.isDefaultExport && symbol.escapedName === InternalSymbolName.Default + return origin && originIsExport(origin) && ( + (origin.isDefaultExport && symbol.escapedName === InternalSymbolName.Default) || + (symbol.escapedName === InternalSymbolName.ExportEquals)) // Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase. ? firstDefined(symbol.declarations, d => isExportAssignment(d) && isIdentifier(d.expression) ? d.expression.text : undefined) || codefix.moduleSymbolToValidIdentifier(origin.moduleSymbol, target) diff --git a/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts new file mode 100644 index 00000000000..c5e87877cfb --- /dev/null +++ b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts @@ -0,0 +1,28 @@ +/// + +// Use `/src` to test that directory names are not included in conversion from module path to identifier. +// @noLib: true + +// @Filename: /src/foo-bar.ts +////export = 0; + +// @Filename: /src/b.ts +////exp/*0*/ +////fooB/*1*/ + +goTo.marker("0"); +const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true }; +const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) export=: 0", kind: "property", hasAction: true }; +verify.completions( + { marker: "0", exact: ["undefined", exportEntry, ...completion.statementKeywordsWithTypes], preferences }, + { marker: "1", includes: exportEntry, preferences } +); +verify.applyCodeActionFromCompletion("0", { + name: "fooBar", + source: "/src/foo-bar", + description: `Import 'fooBar' from module "./foo-bar"`, + newFileContent: `import fooBar = require("./foo-bar"); + +exp +fooB`, +}); \ No newline at end of file