diff --git a/src/services/utilities.ts b/src/services/utilities.ts
index 356c2878c90b8..d9dd9e8c05ec8 100644
--- a/src/services/utilities.ts
+++ b/src/services/utilities.ts
@@ -169,6 +169,7 @@ import {
isExternalModule,
isExternalModuleImportEqualsDeclaration,
isExternalModuleReference,
+ isExternalModuleSymbol,
isFileLevelUniqueName,
isForInStatement,
isForOfStatement,
@@ -4027,7 +4028,13 @@ export function getDefaultLikeExportNameFromDeclaration(symbol: Symbol): string
return tryCast(d.propertyName, isIdentifier)?.text;
}
// GH#52694
- return tryCast(getNameOfDeclaration(d), isIdentifier)?.text;
+ const name = tryCast(getNameOfDeclaration(d), isIdentifier)?.text;
+ if (name) {
+ return name;
+ }
+ if (symbol.parent && !isExternalModuleSymbol(symbol.parent)) {
+ return symbol.parent.getName();
+ }
});
}
diff --git a/tests/cases/fourslash/completionsImportDefaultExportCrash.ts b/tests/cases/fourslash/completionsImportDefaultExportCrash1.ts
similarity index 89%
rename from tests/cases/fourslash/completionsImportDefaultExportCrash.ts
rename to tests/cases/fourslash/completionsImportDefaultExportCrash1.ts
index b6780b1578d1e..776a9fd8c4d4b 100644
--- a/tests/cases/fourslash/completionsImportDefaultExportCrash.ts
+++ b/tests/cases/fourslash/completionsImportDefaultExportCrash1.ts
@@ -35,8 +35,8 @@
verify.completions({
marker: "1",
- // some kind of a check should be added here
+ includes: [{ name: "$" }],
preferences: {
- includeCompletionsForModuleExports: true,
+ includeCompletionsForModuleExports: true,
}
});
diff --git a/tests/cases/fourslash/completionsImportDefaultExportCrash2.ts b/tests/cases/fourslash/completionsImportDefaultExportCrash2.ts
new file mode 100644
index 0000000000000..2e4d28e5a6930
--- /dev/null
+++ b/tests/cases/fourslash/completionsImportDefaultExportCrash2.ts
@@ -0,0 +1,51 @@
+///
+
+// @module: nodenext
+// @allowJs: true
+
+// @Filename: /node_modules/dom7/index.d.ts
+//// export interface Dom7Array {
+//// length: number;
+//// prop(propName: string): any;
+//// }
+////
+//// export interface Dom7 {
+//// (): Dom7Array;
+//// fn: any;
+//// }
+////
+//// declare const Dom7: Dom7;
+////
+//// export {
+//// Dom7 as $,
+//// };
+
+// @Filename: /dom7.js
+//// import * as methods from 'dom7';
+//// Object.keys(methods).forEach((methodName) => {
+//// if (methodName === '$') return;
+//// methods.$.fn[methodName] = methods[methodName];
+//// });
+////
+//// export default methods.$;
+
+// @Filename: /swipe-back.js
+//// /*1*/
+
+verify.completions({
+ marker: "1",
+ includes: [{
+ name: "$",
+ hasAction: true,
+ source: 'dom7',
+ sortText: completion.SortText.AutoImportSuggestions,
+ }, {
+ name: "Dom7",
+ hasAction: true,
+ source: './dom7',
+ sortText: completion.SortText.AutoImportSuggestions,
+ }],
+ preferences: {
+ includeCompletionsForModuleExports: true,
+ }
+});
diff --git a/tests/cases/fourslash/completionsImport_umdDefaultNoCrash1.ts b/tests/cases/fourslash/completionsImport_umdDefaultNoCrash1.ts
new file mode 100644
index 0000000000000..af2fe79e050f7
--- /dev/null
+++ b/tests/cases/fourslash/completionsImport_umdDefaultNoCrash1.ts
@@ -0,0 +1,49 @@
+///
+
+// @moduleResolution: node
+// @allowJs: true
+// @checkJs: true
+
+// @Filename: /node_modules/dottie/package.json
+//// {
+//// "name": "dottie",
+//// "main": "dottie.js"
+//// }
+
+// @Filename: /node_modules/dottie/dottie.js
+//// (function (undefined) {
+//// var root = this;
+////
+//// var Dottie = function () {};
+////
+//// Dottie["default"] = function (object, path, value) {};
+////
+//// if (typeof module !== "undefined" && module.exports) {
+//// exports = module.exports = Dottie;
+//// } else {
+//// root["Dottie"] = Dottie;
+//// root["Dot"] = Dottie;
+////
+//// if (typeof define === "function") {
+//// define([], function () {
+//// return Dottie;
+//// });
+//// }
+//// }
+//// })();
+
+// @Filename: /src/index.js
+//// /**/
+
+verify.completions({
+ marker: "",
+ includes: [
+ {
+ name: "Dottie",
+ hasAction: true,
+ source: "/node_modules/dottie/dottie",
+ sortText: completion.SortText.AutoImportSuggestions,
+ },
+ ],
+ preferences: { includeCompletionsForModuleExports: true },
+});
diff --git a/tests/cases/fourslash/completionsImport_umdDefaultNoCrash2.ts b/tests/cases/fourslash/completionsImport_umdDefaultNoCrash2.ts
new file mode 100644
index 0000000000000..fbd4fce743ba1
--- /dev/null
+++ b/tests/cases/fourslash/completionsImport_umdDefaultNoCrash2.ts
@@ -0,0 +1,43 @@
+///
+
+// @moduleResolution: node
+// @allowJs: true
+// @checkJs: true
+
+// @Filename: /node_modules/dottie/package.json
+//// {
+//// "name": "dottie",
+//// "main": "dottie.js"
+//// }
+
+// @Filename: /node_modules/dottie/dottie.js
+//// (function (undefined) {
+//// var root = this;
+////
+//// var Dottie = function () {};
+////
+//// Dottie["default"] = function (object, path, value) {};
+////
+//// if (typeof module !== "undefined" && module.exports) {
+//// exports = module.exports = Dottie;
+//// } else {
+//// root["Dottie"] = Dottie;
+//// root["Dot"] = Dottie;
+////
+//// if (typeof define === "function") {
+//// define([], function () {
+//// return Dottie;
+//// });
+//// }
+//// }
+//// })();
+
+// @Filename: /src/index.js
+//// import Dottie from 'dottie';
+//// /**/
+
+verify.completions({
+ marker: "",
+ includes: [{ name: "Dottie" }],
+ preferences: { includeCompletionsForModuleExports: true },
+});