fix(36936): fix crash caused by resolving non existent export (#37077)

This commit is contained in:
Alexander T 2020-03-17 22:21:20 +02:00 committed by GitHub
parent f1eb9898fb
commit a510cad873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 132 additions and 2 deletions

View File

@ -3095,8 +3095,8 @@ namespace ts {
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol;
function resolveExternalModuleSymbol(moduleSymbol: Symbol | undefined, dontResolveAlias?: boolean): Symbol | undefined;
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol {
if (moduleSymbol) {
const exportEquals = resolveSymbol(moduleSymbol.exports!.get(InternalSymbolName.ExportEquals), dontResolveAlias);
if (moduleSymbol?.exports) {
const exportEquals = resolveSymbol(moduleSymbol.exports.get(InternalSymbolName.ExportEquals), dontResolveAlias);
const exported = getCommonJsExportEquals(getMergedSymbol(exportEquals), getMergedSymbol(moduleSymbol));
return getMergedSymbol(exported) || moduleSymbol;
}

View File

@ -0,0 +1,26 @@
//// [tests/cases/compiler/tsxResolveExternalModuleExportsTypes.ts] ////
//// [index.d.ts]
declare var a: a.Foo;
declare namespace a {
interface Foo {}
}
export = a;
//// [index.d.ts]
import * as a from 'a';
declare module 'a' {
namespace Test {}
interface Foo {
Test: null;
}
}
//// [foo.tsx]
import { Test } from 'a';
const Foo = (<h1></h1>);
//// [foo.jsx]
var Foo = (<h1></h1>);

View File

@ -0,0 +1,42 @@
=== /node_modules/@types/a/index.d.ts ===
declare var a: a.Foo;
>a : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21), Decl(index.d.ts, 0, 23))
>a : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21))
>Foo : Symbol(a.Foo, Decl(index.d.ts, 1, 21))
declare namespace a {
>a : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21), Decl(index.d.ts, 0, 23))
interface Foo {}
>Foo : Symbol(Foo, Decl(index.d.ts, 1, 21), Decl(index.d.ts, 2, 21))
}
export = a;
>a : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21))
=== /node_modules/@types/b/index.d.ts ===
import * as a from 'a';
>a : Symbol(a, Decl(index.d.ts, 0, 6))
declare module 'a' {
>'a' : Symbol(a, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 21), Decl(index.d.ts, 0, 23))
namespace Test {}
>Test : Symbol(Test, Decl(index.d.ts, 1, 20))
interface Foo {
>Foo : Symbol(Foo, Decl(index.d.ts, 1, 21), Decl(index.d.ts, 2, 21))
Test: null;
>Test : Symbol(Foo.Test, Decl(index.d.ts, 4, 19))
}
}
=== tests/cases/compiler/foo.tsx ===
import { Test } from 'a';
>Test : Symbol(Test, Decl(foo.tsx, 0, 8))
const Foo = (<h1></h1>);
>Foo : Symbol(Foo, Decl(foo.tsx, 1, 5))
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react.d.ts, 2410, 47))
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react.d.ts, 2410, 47))

View File

@ -0,0 +1,38 @@
=== /node_modules/@types/a/index.d.ts ===
declare var a: a.Foo;
>a : import("/node_modules/@types/a/index.d.ts").Foo
>a : any
declare namespace a {
interface Foo {}
}
export = a;
>a : import("/node_modules/@types/a/index.d.ts").Foo
=== /node_modules/@types/b/index.d.ts ===
import * as a from 'a';
>a : a.Foo
declare module 'a' {
>'a' : Foo
namespace Test {}
interface Foo {
Test: null;
>Test : null
>null : null
}
}
=== tests/cases/compiler/foo.tsx ===
import { Test } from 'a';
>Test : null
const Foo = (<h1></h1>);
>Foo : JSX.Element
>(<h1></h1>) : JSX.Element
><h1></h1> : JSX.Element
>h1 : any
>h1 : any

View File

@ -0,0 +1,24 @@
// @module: ES2015
// @jsx: preserve
// @libFiles: react.d.ts,lib.d.ts
// @Filename: /node_modules/@types/a/index.d.ts
declare var a: a.Foo;
declare namespace a {
interface Foo {}
}
export = a;
// @Filename: /node_modules/@types/b/index.d.ts
import * as a from 'a';
declare module 'a' {
namespace Test {}
interface Foo {
Test: null;
}
}
// @Filename: foo.tsx
import { Test } from 'a';
const Foo = (<h1></h1>);