diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index afb1e6364b5aa..a2ea0e2b17dcf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2497,10 +2497,7 @@ namespace ts { function resolveExportByName(moduleSymbol: Symbol, name: __String, sourceNode: TypeOnlyCompatibleAliasDeclaration | undefined, dontResolveAlias: boolean) { const exportValue = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals); - if (exportValue) { - return getPropertyOfType(getTypeOfSymbol(exportValue), name); - } - const exportSymbol = moduleSymbol.exports!.get(name); + const exportSymbol = exportValue ? getPropertyOfType(getTypeOfSymbol(exportValue), name) : moduleSymbol.exports!.get(name); const resolved = resolveSymbol(exportSymbol, dontResolveAlias); markSymbolOfAliasDeclarationIfTypeOnly(sourceNode, exportSymbol, resolved, /*overwriteEmpty*/ false); return resolved; diff --git a/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.js b/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.js new file mode 100644 index 0000000000000..4abb075a8670f --- /dev/null +++ b/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.js @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.ts] //// + +//// [main.ts] +// https://github.com/microsoft/TypeScript/issues/39149 +import a from "a"; +a(); + +//// [external.d.ts] +declare module "b" { + export function a(): void; + export namespace a { + var _a: typeof a; + export { _a as default }; + } + export default a; +} + +declare module "a" { + import { a } from "b"; + export = a; +} + +//// [main.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// https://github.com/microsoft/TypeScript/issues/39149 +const a_1 = __importDefault(require("a")); +a_1.default(); diff --git a/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.symbols b/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.symbols new file mode 100644 index 0000000000000..fe04e6d730e61 --- /dev/null +++ b/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/externalModules/main.ts === +// https://github.com/microsoft/TypeScript/issues/39149 +import a from "a"; +>a : Symbol(a, Decl(main.ts, 1, 6)) + +a(); +>a : Symbol(a, Decl(main.ts, 1, 6)) + +=== tests/cases/conformance/externalModules/external.d.ts === +declare module "b" { +>"b" : Symbol("b", Decl(external.d.ts, 0, 0)) + + export function a(): void; +>a : Symbol(a, Decl(external.d.ts, 0, 20), Decl(external.d.ts, 1, 30)) + + export namespace a { +>a : Symbol(a, Decl(external.d.ts, 0, 20), Decl(external.d.ts, 1, 30)) + + var _a: typeof a; +>_a : Symbol(_a, Decl(external.d.ts, 3, 11)) +>a : Symbol(a, Decl(external.d.ts, 0, 20), Decl(external.d.ts, 1, 30)) + + export { _a as default }; +>_a : Symbol(_a, Decl(external.d.ts, 3, 11)) +>default : Symbol(default, Decl(external.d.ts, 4, 16)) + } + export default a; +>a : Symbol(a, Decl(external.d.ts, 0, 20), Decl(external.d.ts, 1, 30)) +} + +declare module "a" { +>"a" : Symbol("a", Decl(external.d.ts, 7, 1)) + + import { a } from "b"; +>a : Symbol(a, Decl(external.d.ts, 10, 12)) + + export = a; +>a : Symbol(a, Decl(external.d.ts, 10, 12)) +} diff --git a/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.types b/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.types new file mode 100644 index 0000000000000..604eb20912d88 --- /dev/null +++ b/tests/baselines/reference/exportAssignmentOfExportNamespaceWithDefault.types @@ -0,0 +1,40 @@ +=== tests/cases/conformance/externalModules/main.ts === +// https://github.com/microsoft/TypeScript/issues/39149 +import a from "a"; +>a : typeof import("b").a + +a(); +>a() : void +>a : typeof import("b").a + +=== tests/cases/conformance/externalModules/external.d.ts === +declare module "b" { +>"b" : typeof import("b") + + export function a(): void; +>a : typeof a + + export namespace a { +>a : typeof a + + var _a: typeof a; +>_a : typeof a +>a : typeof a + + export { _a as default }; +>_a : typeof a +>default : typeof a + } + export default a; +>a : typeof a +} + +declare module "a" { +>"a" : typeof import("a") + + import { a } from "b"; +>a : typeof a + + export = a; +>a : typeof a +} diff --git a/tests/cases/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.ts b/tests/cases/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.ts new file mode 100644 index 0000000000000..67bcdc3db0a14 --- /dev/null +++ b/tests/cases/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.ts @@ -0,0 +1,22 @@ +// @esModuleInterop: true +// @target: esnext +// @filename: main.ts +// @module: commonjs +// https://github.com/microsoft/TypeScript/issues/39149 +import a from "a"; +a(); + +// @filename: external.d.ts +declare module "b" { + export function a(): void; + export namespace a { + var _a: typeof a; + export { _a as default }; + } + export default a; +} + +declare module "a" { + import { a } from "b"; + export = a; +} \ No newline at end of file