Skip to content

Commit b9ed93e

Browse files
authored
Merge pull request microsoft#41331 from microsoft/fix39149
Fix double alias of complex export/import/default/namespace combination
2 parents 966d978 + f944afd commit b9ed93e

5 files changed

+133
-4
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,10 +2497,7 @@ namespace ts {
24972497

24982498
function resolveExportByName(moduleSymbol: Symbol, name: __String, sourceNode: TypeOnlyCompatibleAliasDeclaration | undefined, dontResolveAlias: boolean) {
24992499
const exportValue = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals);
2500-
if (exportValue) {
2501-
return getPropertyOfType(getTypeOfSymbol(exportValue), name);
2502-
}
2503-
const exportSymbol = moduleSymbol.exports!.get(name);
2500+
const exportSymbol = exportValue ? getPropertyOfType(getTypeOfSymbol(exportValue), name) : moduleSymbol.exports!.get(name);
25042501
const resolved = resolveSymbol(exportSymbol, dontResolveAlias);
25052502
markSymbolOfAliasDeclarationIfTypeOnly(sourceNode, exportSymbol, resolved, /*overwriteEmpty*/ false);
25062503
return resolved;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/conformance/externalModules/exportAssignmentOfExportNamespaceWithDefault.ts] ////
2+
3+
//// [main.ts]
4+
// https://github.com/microsoft/TypeScript/issues/39149
5+
import a from "a";
6+
a();
7+
8+
//// [external.d.ts]
9+
declare module "b" {
10+
export function a(): void;
11+
export namespace a {
12+
var _a: typeof a;
13+
export { _a as default };
14+
}
15+
export default a;
16+
}
17+
18+
declare module "a" {
19+
import { a } from "b";
20+
export = a;
21+
}
22+
23+
//// [main.js]
24+
"use strict";
25+
var __importDefault = (this && this.__importDefault) || function (mod) {
26+
return (mod && mod.__esModule) ? mod : { "default": mod };
27+
};
28+
Object.defineProperty(exports, "__esModule", { value: true });
29+
// https://github.com/microsoft/TypeScript/issues/39149
30+
const a_1 = __importDefault(require("a"));
31+
a_1.default();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== tests/cases/conformance/externalModules/main.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/39149
3+
import a from "a";
4+
>a : Symbol(a, Decl(main.ts, 1, 6))
5+
6+
a();
7+
>a : Symbol(a, Decl(main.ts, 1, 6))
8+
9+
=== tests/cases/conformance/externalModules/external.d.ts ===
10+
declare module "b" {
11+
>"b" : Symbol("b", Decl(external.d.ts, 0, 0))
12+
13+
export function a(): void;
14+
>a : Symbol(a, Decl(external.d.ts, 0, 20), Decl(external.d.ts, 1, 30))
15+
16+
export namespace a {
17+
>a : Symbol(a, Decl(external.d.ts, 0, 20), Decl(external.d.ts, 1, 30))
18+
19+
var _a: typeof a;
20+
>_a : Symbol(_a, Decl(external.d.ts, 3, 11))
21+
>a : Symbol(a, Decl(external.d.ts, 0, 20), Decl(external.d.ts, 1, 30))
22+
23+
export { _a as default };
24+
>_a : Symbol(_a, Decl(external.d.ts, 3, 11))
25+
>default : Symbol(default, Decl(external.d.ts, 4, 16))
26+
}
27+
export default a;
28+
>a : Symbol(a, Decl(external.d.ts, 0, 20), Decl(external.d.ts, 1, 30))
29+
}
30+
31+
declare module "a" {
32+
>"a" : Symbol("a", Decl(external.d.ts, 7, 1))
33+
34+
import { a } from "b";
35+
>a : Symbol(a, Decl(external.d.ts, 10, 12))
36+
37+
export = a;
38+
>a : Symbol(a, Decl(external.d.ts, 10, 12))
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== tests/cases/conformance/externalModules/main.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/39149
3+
import a from "a";
4+
>a : typeof import("b").a
5+
6+
a();
7+
>a() : void
8+
>a : typeof import("b").a
9+
10+
=== tests/cases/conformance/externalModules/external.d.ts ===
11+
declare module "b" {
12+
>"b" : typeof import("b")
13+
14+
export function a(): void;
15+
>a : typeof a
16+
17+
export namespace a {
18+
>a : typeof a
19+
20+
var _a: typeof a;
21+
>_a : typeof a
22+
>a : typeof a
23+
24+
export { _a as default };
25+
>_a : typeof a
26+
>default : typeof a
27+
}
28+
export default a;
29+
>a : typeof a
30+
}
31+
32+
declare module "a" {
33+
>"a" : typeof import("a")
34+
35+
import { a } from "b";
36+
>a : typeof a
37+
38+
export = a;
39+
>a : typeof a
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @esModuleInterop: true
2+
// @target: esnext
3+
// @filename: main.ts
4+
// @module: commonjs
5+
// https://github.com/microsoft/TypeScript/issues/39149
6+
import a from "a";
7+
a();
8+
9+
// @filename: external.d.ts
10+
declare module "b" {
11+
export function a(): void;
12+
export namespace a {
13+
var _a: typeof a;
14+
export { _a as default };
15+
}
16+
export default a;
17+
}
18+
19+
declare module "a" {
20+
import { a } from "b";
21+
export = a;
22+
}

0 commit comments

Comments
 (0)