Fix crash when looking for __esModule during symbol table merging (#52554)

This commit is contained in:
Andrew Branch 2023-02-02 09:27:10 -08:00 committed by GitHub
parent 30993855fd
commit 4ec9b2f8d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 120 additions and 1 deletions

View File

@ -3884,7 +3884,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function resolveExportByName(moduleSymbol: Symbol, name: __String, sourceNode: TypeOnlyCompatibleAliasDeclaration | undefined, dontResolveAlias: boolean) {
const exportValue = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals);
const exportSymbol = exportValue ? getPropertyOfType(getTypeOfSymbol(exportValue), name) : moduleSymbol.exports!.get(name);
const exportSymbol = exportValue
? getPropertyOfType(getTypeOfSymbol(exportValue), name, /*skipObjectFunctionPropertyAugment*/ true)
: moduleSymbol.exports!.get(name);
const resolved = resolveSymbol(exportSymbol, dontResolveAlias);
markSymbolOfAliasDeclarationIfTypeOnly(sourceNode, exportSymbol, resolved, /*overwriteEmpty*/ false);
return resolved;

View File

@ -0,0 +1,37 @@
=== tests/cases/compiler/bar.d.ts ===
import * as foo from './foo'
>foo : Symbol(foo, Decl(bar.d.ts, 0, 6))
export as namespace foo
>foo : Symbol(foo, Decl(bar.d.ts, 0, 28))
export = foo;
>foo : Symbol(foo, Decl(bar.d.ts, 0, 6))
declare global {
>global : Symbol(global, Decl(bar.d.ts, 2, 13))
const foo: typeof foo;
>foo : Symbol(foo, Decl(foo.d.ts, 7, 13), Decl(bar.d.ts, 5, 9))
>foo : Symbol(foo, Decl(foo.d.ts, 7, 13), Decl(bar.d.ts, 5, 9))
}
=== tests/cases/compiler/foo.d.ts ===
interface Root {
>Root : Symbol(Root, Decl(foo.d.ts, 0, 0))
/**
* A .default property for ES6 default import compatibility
*/
default: Root;
>default : Symbol(Root.default, Decl(foo.d.ts, 0, 16))
>Root : Symbol(Root, Decl(foo.d.ts, 0, 0))
}
declare const root: Root;
>root : Symbol(root, Decl(foo.d.ts, 7, 13))
>Root : Symbol(Root, Decl(foo.d.ts, 0, 0))
export = root;
>root : Symbol(root, Decl(foo.d.ts, 7, 13))

View File

@ -0,0 +1,33 @@
=== tests/cases/compiler/bar.d.ts ===
import * as foo from './foo'
>foo : { default: Root; }
export as namespace foo
>foo : { default: Root; }
export = foo;
>foo : { default: Root; }
declare global {
>global : typeof global
const foo: typeof foo;
>foo : Root
>foo : Root
}
=== tests/cases/compiler/foo.d.ts ===
interface Root {
/**
* A .default property for ES6 default import compatibility
*/
default: Root;
>default : Root
}
declare const root: Root;
>root : Root
export = root;
>root : Root

View File

@ -0,0 +1,21 @@
// @esModuleInterop: true
// @Filename: bar.d.ts
import * as foo from './foo'
export as namespace foo
export = foo;
declare global {
const foo: typeof foo;
}
// @Filename: foo.d.ts
interface Root {
/**
* A .default property for ES6 default import compatibility
*/
default: Root;
}
declare const root: Root;
export = root;

View File

@ -0,0 +1,26 @@
/// <reference path='fourslash.ts' />
// @Filename: bar.ts
//// import * as foo from './foo'
//// export as namespace foo
//// export = foo;
////
//// declare global {
//// const foo: typeof foo;
//// }
// @Filename: foo.d.ts
//// interface Root {
//// /**
//// * A .default property for ES6 default import compatibility
//// */
//// default: Root;
//// }
////
//// declare const root: Root;
//// export = root;
goTo.file("bar.ts");
verify.not.codeFixAvailable();
goTo.file("foo.d.ts");
verify.not.codeFixAvailable();