Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3882,7 +3882,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be adding a note or something just as a reminder would be good. (that its called for default or __esModule

? getPropertyOfType(getTypeOfSymbol(exportValue), name, /*skipObjectFunctionPropertyAugment*/ true)
: moduleSymbol.exports!.get(name);
const resolved = resolveSymbol(exportSymbol, dontResolveAlias);
markSymbolOfAliasDeclarationIfTypeOnly(sourceNode, exportSymbol, resolved, /*overwriteEmpty*/ false);
return resolved;
Expand Down
37 changes: 37 additions & 0 deletions tests/baselines/reference/crashDeclareGlobalTypeofExport.symbols
Original file line number Diff line number Diff line change
@@ -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))

33 changes: 33 additions & 0 deletions tests/baselines/reference/crashDeclareGlobalTypeofExport.types
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions tests/cases/compiler/crashDeclareGlobalTypeofExport.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 26 additions & 0 deletions tests/cases/fourslash/codefixCrashExportGlobal.ts
Original file line number Diff line number Diff line change
@@ -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();