Skip to content

Fix double alias of complex export/import/default/namespace combination #41331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2020
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
5 changes: 1 addition & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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;
}