Skip to content

Commit 6e54cbd

Browse files
committed
Handle generating action for export equals with anonymous symbol
Fixes microsoft#28845
1 parent e5708e1 commit 6e54cbd

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/services/completions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ namespace ts.Completions {
367367
}
368368

369369
function getSymbolName(symbol: Symbol, origin: SymbolOriginInfo | undefined, target: ScriptTarget): string {
370-
return origin && originIsExport(origin) && origin.isDefaultExport && symbol.escapedName === InternalSymbolName.Default
370+
return origin && originIsExport(origin) && (
371+
(origin.isDefaultExport && symbol.escapedName === InternalSymbolName.Default) ||
372+
(symbol.escapedName === InternalSymbolName.ExportEquals))
371373
// Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase.
372374
? firstDefined(symbol.declarations, d => isExportAssignment(d) && isIdentifier(d.expression) ? d.expression.text : undefined)
373375
|| codefix.moduleSymbolToValidIdentifier(origin.moduleSymbol, target)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// Use `/src` to test that directory names are not included in conversion from module path to identifier.
4+
// @noLib: true
5+
6+
// @Filename: /src/foo-bar.ts
7+
////export = 0;
8+
9+
// @Filename: /src/b.ts
10+
////exp/*0*/
11+
////fooB/*1*/
12+
13+
goTo.marker("0");
14+
const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true };
15+
const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) export=: 0", kind: "property", hasAction: true };
16+
verify.completions(
17+
{ marker: "0", exact: ["undefined", exportEntry, ...completion.statementKeywordsWithTypes], preferences },
18+
{ marker: "1", includes: exportEntry, preferences }
19+
);
20+
verify.applyCodeActionFromCompletion("0", {
21+
name: "fooBar",
22+
source: "/src/foo-bar",
23+
description: `Import 'fooBar' from module "./foo-bar"`,
24+
newFileContent: `import fooBar = require("./foo-bar");
25+
26+
exp
27+
fooB`,
28+
});

0 commit comments

Comments
 (0)