Skip to content

Commit a510cad

Browse files
authored
fix(36936): fix crash caused by resolving non existent export (#37077)
1 parent f1eb989 commit a510cad

File tree

5 files changed

+132
-2
lines changed

5 files changed

+132
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,8 +3095,8 @@ namespace ts {
30953095
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol;
30963096
function resolveExternalModuleSymbol(moduleSymbol: Symbol | undefined, dontResolveAlias?: boolean): Symbol | undefined;
30973097
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol {
3098-
if (moduleSymbol) {
3099-
const exportEquals = resolveSymbol(moduleSymbol.exports!.get(InternalSymbolName.ExportEquals), dontResolveAlias);
3098+
if (moduleSymbol?.exports) {
3099+
const exportEquals = resolveSymbol(moduleSymbol.exports.get(InternalSymbolName.ExportEquals), dontResolveAlias);
31003100
const exported = getCommonJsExportEquals(getMergedSymbol(exportEquals), getMergedSymbol(moduleSymbol));
31013101
return getMergedSymbol(exported) || moduleSymbol;
31023102
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [tests/cases/compiler/tsxResolveExternalModuleExportsTypes.ts] ////
2+
3+
//// [index.d.ts]
4+
declare var a: a.Foo;
5+
declare namespace a {
6+
interface Foo {}
7+
}
8+
export = a;
9+
10+
//// [index.d.ts]
11+
import * as a from 'a';
12+
declare module 'a' {
13+
namespace Test {}
14+
15+
interface Foo {
16+
Test: null;
17+
}
18+
}
19+
20+
//// [foo.tsx]
21+
import { Test } from 'a';
22+
const Foo = (<h1></h1>);
23+
24+
25+
//// [foo.jsx]
26+
var Foo = (<h1></h1>);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=== /node_modules/@types/a/index.d.ts ===
2+
declare var a: a.Foo;
3+
>a : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21), Decl(index.d.ts, 0, 23))
4+
>a : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21))
5+
>Foo : Symbol(a.Foo, Decl(index.d.ts, 1, 21))
6+
7+
declare namespace a {
8+
>a : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21), Decl(index.d.ts, 0, 23))
9+
10+
interface Foo {}
11+
>Foo : Symbol(Foo, Decl(index.d.ts, 1, 21), Decl(index.d.ts, 2, 21))
12+
}
13+
export = a;
14+
>a : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21))
15+
16+
=== /node_modules/@types/b/index.d.ts ===
17+
import * as a from 'a';
18+
>a : Symbol(a, Decl(index.d.ts, 0, 6))
19+
20+
declare module 'a' {
21+
>'a' : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21), Decl(index.d.ts, 0, 23))
22+
23+
namespace Test {}
24+
>Test : Symbol(Test, Decl(index.d.ts, 1, 20))
25+
26+
interface Foo {
27+
>Foo : Symbol(Foo, Decl(index.d.ts, 1, 21), Decl(index.d.ts, 2, 21))
28+
29+
Test: null;
30+
>Test : Symbol(Foo.Test, Decl(index.d.ts, 4, 19))
31+
}
32+
}
33+
34+
=== tests/cases/compiler/foo.tsx ===
35+
import { Test } from 'a';
36+
>Test : Symbol(Test, Decl(foo.tsx, 0, 8))
37+
38+
const Foo = (<h1></h1>);
39+
>Foo : Symbol(Foo, Decl(foo.tsx, 1, 5))
40+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react.d.ts, 2410, 47))
41+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react.d.ts, 2410, 47))
42+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
=== /node_modules/@types/a/index.d.ts ===
2+
declare var a: a.Foo;
3+
>a : import("/node_modules/@types/a/index.d.ts").Foo
4+
>a : any
5+
6+
declare namespace a {
7+
interface Foo {}
8+
}
9+
export = a;
10+
>a : import("/node_modules/@types/a/index.d.ts").Foo
11+
12+
=== /node_modules/@types/b/index.d.ts ===
13+
import * as a from 'a';
14+
>a : a.Foo
15+
16+
declare module 'a' {
17+
>'a' : Foo
18+
19+
namespace Test {}
20+
21+
interface Foo {
22+
Test: null;
23+
>Test : null
24+
>null : null
25+
}
26+
}
27+
28+
=== tests/cases/compiler/foo.tsx ===
29+
import { Test } from 'a';
30+
>Test : null
31+
32+
const Foo = (<h1></h1>);
33+
>Foo : JSX.Element
34+
>(<h1></h1>) : JSX.Element
35+
><h1></h1> : JSX.Element
36+
>h1 : any
37+
>h1 : any
38+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @module: ES2015
2+
// @jsx: preserve
3+
// @libFiles: react.d.ts,lib.d.ts
4+
5+
// @Filename: /node_modules/@types/a/index.d.ts
6+
declare var a: a.Foo;
7+
declare namespace a {
8+
interface Foo {}
9+
}
10+
export = a;
11+
12+
// @Filename: /node_modules/@types/b/index.d.ts
13+
import * as a from 'a';
14+
declare module 'a' {
15+
namespace Test {}
16+
17+
interface Foo {
18+
Test: null;
19+
}
20+
}
21+
22+
// @Filename: foo.tsx
23+
import { Test } from 'a';
24+
const Foo = (<h1></h1>);

0 commit comments

Comments
 (0)