mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Fix crash when exporting+aliasing globalThis inside declare global (#34408)
* global module:Fix crash when exporting+aliasing globalThis * Fix another globalThis crash find-all-refs assumed that an export inside a `declare x` was always an ambient module, but it is not -- `declare global` does not allow `export`, so find-all-refs shouldn't return any refs for this error case.
This commit is contained in:
committed by
GitHub
parent
a685ac426c
commit
29f9493d87
@@ -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 {
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//// [globalThisGlobalExportAsGlobal.ts]
|
||||
// https://github.com/microsoft/TypeScript/issues/33754
|
||||
declare global {
|
||||
export { globalThis as global }
|
||||
}
|
||||
|
||||
|
||||
//// [globalThisGlobalExportAsGlobal.js]
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// https://github.com/microsoft/TypeScript/issues/33754
|
||||
declare global {
|
||||
export { globalThis as global }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////declare global {
|
||||
//// export { globalThis as [|global|] }
|
||||
////}
|
||||
|
||||
for (const r of test.ranges()) {
|
||||
verify.documentHighlightsOf(r, [r]);
|
||||
}
|
||||
Reference in New Issue
Block a user