Skip to content
Draft
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
7 changes: 6 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5726,7 +5726,12 @@ func (c *Checker) checkExportSpecifier(node *ast.ExportSpecifierNode) {
}
// find immediate value referenced by exported name (SymbolFlags.Alias is set so we don't chase down aliases)
symbol := c.resolveName(exportedName, exportedName.Text(), ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace|ast.SymbolFlagsAlias, nil /*nameNotFoundMessage*/, true /*isUse*/, false)
if symbol != nil && (symbol == c.undefinedSymbol || symbol == c.globalThisSymbol || symbol.Declarations != nil && ast.IsGlobalSourceFile(ast.GetDeclarationContainer(symbol.Declarations[0]))) {
isGlobalDeclaration := false
if symbol != nil && symbol.Declarations != nil {
declarationContainer := ast.GetDeclarationContainer(symbol.Declarations[0])
isGlobalDeclaration = ast.IsGlobalSourceFile(declarationContainer) || ast.IsModuleBlock(declarationContainer) && ast.IsGlobalScopeAugmentation(declarationContainer.Parent)
}
if symbol != nil && (symbol == c.undefinedSymbol || symbol == c.globalThisSymbol || isGlobalDeclaration) {
c.error(exportedName, diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module, exportedName.Text())
} else {
c.markLinkedReferences(node, ReferenceHintExportSpecifier, nil /*propSymbol*/, nil /*parentType*/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exportSpecifierForAGlobalAugmentation.ts(5,10): error TS2661: Cannot export 'XYZ'. Only local declarations can be exported from a module.


==== exportSpecifierForAGlobalAugmentation.ts (1 errors) ====
declare global {
var XYZ: number;
}

export { XYZ };
~~~
!!! error TS2661: Cannot export 'XYZ'. Only local declarations can be exported from a module.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//// [tests/cases/compiler/exportSpecifierForAGlobalAugmentation.ts] ////

//// [exportSpecifierForAGlobalAugmentation.ts]
declare global {
var XYZ: number;
}

export { XYZ };


//// [exportSpecifierForAGlobalAugmentation.js]
export { XYZ };
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/exportSpecifierForAGlobalAugmentation.ts] ////

=== exportSpecifierForAGlobalAugmentation.ts ===
declare global {
>global : Symbol(global, Decl(exportSpecifierForAGlobalAugmentation.ts, 0, 0))

var XYZ: number;
>XYZ : Symbol(XYZ, Decl(exportSpecifierForAGlobalAugmentation.ts, 1, 7))
}

export { XYZ };
>XYZ : Symbol(XYZ, Decl(exportSpecifierForAGlobalAugmentation.ts, 4, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/exportSpecifierForAGlobalAugmentation.ts] ////

=== exportSpecifierForAGlobalAugmentation.ts ===
declare global {
>global : typeof global

var XYZ: number;
>XYZ : number
}

export { XYZ };
>XYZ : number

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare global {
var XYZ: number;
}

export { XYZ };