Skip to content
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32454,7 +32454,7 @@ namespace ts {
// find immediate value referenced by exported name (SymbolFlags.Alias is set so we don't chase down aliases)
const symbol = resolveName(exportedName, exportedName.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias,
/*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ true);
if (symbol && (symbol === undefinedSymbol || isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0])))) {
if (symbol && (symbol === undefinedSymbol || symbol === globalThisSymbol || isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0])))) {
error(exportedName, Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module, idText(exportedName));
}
else {
Expand Down
6 changes: 4 additions & 2 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,10 @@ namespace ts.FindAllReferences.Core {
|| exportSpecifier.name.originalKeywordKind === SyntaxKind.DefaultKeyword;
const exportKind = isDefaultExport ? ExportKind.Default : ExportKind.Named;
const exportSymbol = Debug.assertDefined(exportSpecifier.symbol);
const exportInfo = Debug.assertDefined(getExportInfo(exportSymbol, exportKind, state.checker));
searchForImportsOfExport(referenceLocation, exportSymbol, exportInfo, state);
const exportInfo = getExportInfo(exportSymbol, exportKind, state.checker);
if (exportInfo) {
searchForImportsOfExport(referenceLocation, exportSymbol, exportInfo, state);
}
}

// At `export { x } from "foo"`, also search for the imported symbol `"foo".x`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests/cases/conformance/es2019/globalThisGlobalExportAsGlobal.ts(2,9): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.
tests/cases/conformance/es2019/globalThisGlobalExportAsGlobal.ts(3,14): error TS2661: Cannot export 'globalThis'. Only local declarations can be exported from a module.


==== tests/cases/conformance/es2019/globalThisGlobalExportAsGlobal.ts (2 errors) ====
// https://github.com/microsoft/TypeScript/issues/33754
declare global {
~~~~~~
!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.
export { globalThis as global }
~~~~~~~~~~
!!! error TS2661: Cannot export 'globalThis'. Only local declarations can be exported from a module.
}

8 changes: 8 additions & 0 deletions tests/baselines/reference/globalThisGlobalExportAsGlobal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [globalThisGlobalExportAsGlobal.ts]
// https://github.com/microsoft/TypeScript/issues/33754
declare global {
export { globalThis as global }
}


//// [globalThisGlobalExportAsGlobal.js]
10 changes: 10 additions & 0 deletions tests/baselines/reference/globalThisGlobalExportAsGlobal.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/es2019/globalThisGlobalExportAsGlobal.ts ===
// https://github.com/microsoft/TypeScript/issues/33754
declare global {
>global : Symbol(global, Decl(globalThisGlobalExportAsGlobal.ts, 0, 0))

export { globalThis as global }
>globalThis : Symbol(globalThis)
>global : Symbol(global, Decl(globalThisGlobalExportAsGlobal.ts, 2, 12))
}

10 changes: 10 additions & 0 deletions tests/baselines/reference/globalThisGlobalExportAsGlobal.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/es2019/globalThisGlobalExportAsGlobal.ts ===
// https://github.com/microsoft/TypeScript/issues/33754
declare global {
>global : typeof global

export { globalThis as global }
>globalThis : typeof globalThis
>global : typeof globalThis
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://github.com/microsoft/TypeScript/issues/33754
declare global {
export { globalThis as global }
}
9 changes: 9 additions & 0 deletions tests/cases/fourslash/documentHighlightsInvalidGlobalThis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

////declare global {
//// export { globalThis as [|global|] }
////}

for (const r of test.ranges()) {
verify.documentHighlightsOf(r, [r]);
}