mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Fix crash when looking for __esModule during symbol table merging (#52554)
This commit is contained in:
parent
30993855fd
commit
4ec9b2f8d7
@ -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;
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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
|
||||
|
||||
21
tests/cases/compiler/crashDeclareGlobalTypeofExport.ts
Normal file
21
tests/cases/compiler/crashDeclareGlobalTypeofExport.ts
Normal 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;
|
||||
26
tests/cases/fourslash/codefixCrashExportGlobal.ts
Normal file
26
tests/cases/fourslash/codefixCrashExportGlobal.ts
Normal 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();
|
||||
Loading…
x
Reference in New Issue
Block a user