@@ -279,6 +279,7 @@ namespace ts {
279
279
Debug . assert ( ! hasDynamicName ( node ) ) ;
280
280
281
281
const isDefaultExport = node . flags & NodeFlags . Default ;
282
+
282
283
// The exported symbol for an export default function/class node is always named "default"
283
284
const name = isDefaultExport && parent ? "default" : getDeclarationName ( node ) ;
284
285
@@ -753,6 +754,7 @@ namespace ts {
753
754
case SyntaxKind . GetAccessor :
754
755
case SyntaxKind . SetAccessor :
755
756
case SyntaxKind . FunctionType :
757
+ case SyntaxKind . JSDocFunctionType :
756
758
case SyntaxKind . ConstructorType :
757
759
case SyntaxKind . FunctionExpression :
758
760
case SyntaxKind . ArrowFunction :
@@ -900,7 +902,12 @@ namespace ts {
900
902
if ( node . flags & NodeFlags . Export ) {
901
903
errorOnFirstToken ( node , Diagnostics . export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible ) ;
902
904
}
903
- declareSymbolAndAddToSymbolTable ( node , SymbolFlags . ValueModule , SymbolFlags . ValueModuleExcludes ) ;
905
+ if ( isExternalModuleAugmentation ( node ) ) {
906
+ declareSymbolAndAddToSymbolTable ( node , SymbolFlags . NamespaceModule , SymbolFlags . NamespaceModuleExcludes ) ;
907
+ }
908
+ else {
909
+ declareSymbolAndAddToSymbolTable ( node , SymbolFlags . ValueModule , SymbolFlags . ValueModuleExcludes ) ;
910
+ }
904
911
}
905
912
else {
906
913
const state = getModuleInstanceState ( node ) ;
@@ -1349,6 +1356,8 @@ namespace ts {
1349
1356
case SyntaxKind . ImportSpecifier :
1350
1357
case SyntaxKind . ExportSpecifier :
1351
1358
return declareSymbolAndAddToSymbolTable ( < Declaration > node , SymbolFlags . Alias , SymbolFlags . AliasExcludes ) ;
1359
+ case SyntaxKind . GlobalModuleExportDeclaration :
1360
+ return bindGlobalModuleExportDeclaration ( < GlobalModuleExportDeclaration > node ) ;
1352
1361
case SyntaxKind . ImportClause :
1353
1362
return bindImportClause ( < ImportClause > node ) ;
1354
1363
case SyntaxKind . ExportDeclaration :
@@ -1398,6 +1407,33 @@ namespace ts {
1398
1407
}
1399
1408
}
1400
1409
1410
+ function bindGlobalModuleExportDeclaration ( node : GlobalModuleExportDeclaration ) {
1411
+ if ( node . modifiers && node . modifiers . length ) {
1412
+ file . bindDiagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Modifiers_cannot_appear_here ) ) ;
1413
+ }
1414
+
1415
+ if ( node . parent . kind !== SyntaxKind . SourceFile ) {
1416
+ file . bindDiagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Global_module_exports_may_only_appear_at_top_level ) ) ;
1417
+ return ;
1418
+ }
1419
+ else {
1420
+ const parent = node . parent as SourceFile ;
1421
+
1422
+ if ( ! isExternalModule ( parent ) ) {
1423
+ file . bindDiagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Global_module_exports_may_only_appear_in_module_files ) ) ;
1424
+ return ;
1425
+ }
1426
+
1427
+ if ( ! parent . isDeclarationFile ) {
1428
+ file . bindDiagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Global_module_exports_may_only_appear_in_declaration_files ) ) ;
1429
+ return ;
1430
+ }
1431
+ }
1432
+
1433
+ file . symbol . globalExports = file . symbol . globalExports || { } ;
1434
+ declareSymbol ( file . symbol . globalExports , file . symbol , node , SymbolFlags . Alias , SymbolFlags . AliasExcludes ) ;
1435
+ }
1436
+
1401
1437
function bindExportDeclaration ( node : ExportDeclaration ) {
1402
1438
if ( ! container . symbol || ! container . symbol . exports ) {
1403
1439
// Export * in some sort of block construct
@@ -1432,7 +1468,7 @@ namespace ts {
1432
1468
function bindModuleExportsAssignment ( node : BinaryExpression ) {
1433
1469
// 'module.exports = expr' assignment
1434
1470
setCommonJsModuleIndicator ( node ) ;
1435
- bindExportAssignment ( node ) ;
1471
+ declareSymbol ( file . symbol . exports , file . symbol , node , SymbolFlags . Property | SymbolFlags . Export | SymbolFlags . ValueModule , SymbolFlags . None ) ;
1436
1472
}
1437
1473
1438
1474
function bindThisPropertyAssignment ( node : BinaryExpression ) {
0 commit comments