Skip to content

Commit 4ec9b2f

Browse files
authored
Fix crash when looking for __esModule during symbol table merging (#52554)
1 parent 3099385 commit 4ec9b2f

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3884,7 +3884,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
38843884

38853885
function resolveExportByName(moduleSymbol: Symbol, name: __String, sourceNode: TypeOnlyCompatibleAliasDeclaration | undefined, dontResolveAlias: boolean) {
38863886
const exportValue = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals);
3887-
const exportSymbol = exportValue ? getPropertyOfType(getTypeOfSymbol(exportValue), name) : moduleSymbol.exports!.get(name);
3887+
const exportSymbol = exportValue
3888+
? getPropertyOfType(getTypeOfSymbol(exportValue), name, /*skipObjectFunctionPropertyAugment*/ true)
3889+
: moduleSymbol.exports!.get(name);
38883890
const resolved = resolveSymbol(exportSymbol, dontResolveAlias);
38893891
markSymbolOfAliasDeclarationIfTypeOnly(sourceNode, exportSymbol, resolved, /*overwriteEmpty*/ false);
38903892
return resolved;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/bar.d.ts ===
2+
import * as foo from './foo'
3+
>foo : Symbol(foo, Decl(bar.d.ts, 0, 6))
4+
5+
export as namespace foo
6+
>foo : Symbol(foo, Decl(bar.d.ts, 0, 28))
7+
8+
export = foo;
9+
>foo : Symbol(foo, Decl(bar.d.ts, 0, 6))
10+
11+
declare global {
12+
>global : Symbol(global, Decl(bar.d.ts, 2, 13))
13+
14+
const foo: typeof foo;
15+
>foo : Symbol(foo, Decl(foo.d.ts, 7, 13), Decl(bar.d.ts, 5, 9))
16+
>foo : Symbol(foo, Decl(foo.d.ts, 7, 13), Decl(bar.d.ts, 5, 9))
17+
}
18+
19+
=== tests/cases/compiler/foo.d.ts ===
20+
interface Root {
21+
>Root : Symbol(Root, Decl(foo.d.ts, 0, 0))
22+
23+
/**
24+
* A .default property for ES6 default import compatibility
25+
*/
26+
default: Root;
27+
>default : Symbol(Root.default, Decl(foo.d.ts, 0, 16))
28+
>Root : Symbol(Root, Decl(foo.d.ts, 0, 0))
29+
}
30+
31+
declare const root: Root;
32+
>root : Symbol(root, Decl(foo.d.ts, 7, 13))
33+
>Root : Symbol(Root, Decl(foo.d.ts, 0, 0))
34+
35+
export = root;
36+
>root : Symbol(root, Decl(foo.d.ts, 7, 13))
37+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/bar.d.ts ===
2+
import * as foo from './foo'
3+
>foo : { default: Root; }
4+
5+
export as namespace foo
6+
>foo : { default: Root; }
7+
8+
export = foo;
9+
>foo : { default: Root; }
10+
11+
declare global {
12+
>global : typeof global
13+
14+
const foo: typeof foo;
15+
>foo : Root
16+
>foo : Root
17+
}
18+
19+
=== tests/cases/compiler/foo.d.ts ===
20+
interface Root {
21+
/**
22+
* A .default property for ES6 default import compatibility
23+
*/
24+
default: Root;
25+
>default : Root
26+
}
27+
28+
declare const root: Root;
29+
>root : Root
30+
31+
export = root;
32+
>root : Root
33+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @esModuleInterop: true
2+
3+
// @Filename: bar.d.ts
4+
import * as foo from './foo'
5+
export as namespace foo
6+
export = foo;
7+
8+
declare global {
9+
const foo: typeof foo;
10+
}
11+
12+
// @Filename: foo.d.ts
13+
interface Root {
14+
/**
15+
* A .default property for ES6 default import compatibility
16+
*/
17+
default: Root;
18+
}
19+
20+
declare const root: Root;
21+
export = root;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: bar.ts
4+
//// import * as foo from './foo'
5+
//// export as namespace foo
6+
//// export = foo;
7+
////
8+
//// declare global {
9+
//// const foo: typeof foo;
10+
//// }
11+
12+
// @Filename: foo.d.ts
13+
//// interface Root {
14+
//// /**
15+
//// * A .default property for ES6 default import compatibility
16+
//// */
17+
//// default: Root;
18+
//// }
19+
////
20+
//// declare const root: Root;
21+
//// export = root;
22+
23+
goTo.file("bar.ts");
24+
verify.not.codeFixAvailable();
25+
goTo.file("foo.d.ts");
26+
verify.not.codeFixAvailable();

0 commit comments

Comments
 (0)