@@ -133,12 +133,6 @@ class TypeAlias {
133
133
type : CommonTypeNode ;
134
134
}
135
135
136
- /** Represents a module-level export. */
137
- class ModuleExport {
138
- element : Element ;
139
- identifier : IdentifierExpression ;
140
- }
141
-
142
136
/** Represents the kind of an operator overload. */
143
137
export enum OperatorKind {
144
138
INVALID ,
@@ -325,8 +319,8 @@ export class Program extends DiagnosticEmitter {
325
319
typeAliases : Map < string , TypeAlias > = new Map ( ) ;
326
320
/** File-level exports by exported name. */
327
321
fileLevelExports : Map < string , Element > = new Map ( ) ;
328
- /** Module-level exports by exported name. */
329
- moduleLevelExports : Map < string , ModuleExport > = new Map ( ) ;
322
+ /** Module-level exports by exported name. (Not related to ES6 modules.) */
323
+ moduleLevelExports : Map < string , Element > = new Map ( ) ;
330
324
331
325
/** ArrayBuffer instance reference. */
332
326
arrayBufferInstance : Class | null = null ;
@@ -648,15 +642,13 @@ export class Program extends DiagnosticEmitter {
648
642
}
649
643
650
644
// register 'main' if present
651
- if ( this . moduleLevelExports . has ( "main" ) ) {
652
- let element = ( < ModuleExport > this . moduleLevelExports . get ( "main" ) ) . element ;
653
- if (
654
- element . kind == ElementKind . FUNCTION_PROTOTYPE &&
655
- ! ( < FunctionPrototype > element ) . isAny ( CommonFlags . GENERIC | CommonFlags . AMBIENT )
656
- ) {
657
- ( < FunctionPrototype > element ) . set ( CommonFlags . MAIN ) ;
658
- this . mainFunction = < FunctionPrototype > element ;
659
- }
645
+ let mainElement = this . moduleLevelExports . get ( "main" ) ;
646
+ if ( mainElement &&
647
+ mainElement . kind == ElementKind . FUNCTION_PROTOTYPE &&
648
+ ! ( < FunctionPrototype > mainElement ) . isAny ( CommonFlags . GENERIC | CommonFlags . AMBIENT )
649
+ ) {
650
+ ( < FunctionPrototype > mainElement ) . set ( CommonFlags . MAIN ) ;
651
+ this . mainFunction = < FunctionPrototype > mainElement ;
660
652
}
661
653
662
654
// register 'abort' if present
@@ -932,18 +924,15 @@ export class Program extends DiagnosticEmitter {
932
924
this . currentFilespace . members . set ( simpleName , prototype ) ;
933
925
if ( prototype . is ( CommonFlags . EXPORT ) && declaration . range . source . isEntry ) {
934
926
if ( this . moduleLevelExports . has ( simpleName ) ) {
935
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
927
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
936
928
this . error (
937
929
DiagnosticCode . Export_declaration_conflicts_with_exported_declaration_of_0 ,
938
- declaration . name . range , existingExport . element . internalName
930
+ declaration . name . range , existingExport . internalName
939
931
) ;
940
932
return ;
941
933
}
942
934
prototype . set ( CommonFlags . MODULE_EXPORT ) ;
943
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
944
- element : prototype ,
945
- identifier : declaration . name
946
- } ) ;
935
+ this . moduleLevelExports . set ( simpleName , prototype ) ;
947
936
}
948
937
}
949
938
@@ -1388,18 +1377,15 @@ export class Program extends DiagnosticEmitter {
1388
1377
this . currentFilespace . members . set ( simpleName , element ) ;
1389
1378
if ( declaration . range . source . isEntry ) {
1390
1379
if ( this . moduleLevelExports . has ( simpleName ) ) {
1391
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
1380
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
1392
1381
this . error (
1393
1382
DiagnosticCode . Export_declaration_conflicts_with_exported_declaration_of_0 ,
1394
- declaration . name . range , existingExport . element . internalName
1383
+ declaration . name . range , existingExport . internalName
1395
1384
) ;
1396
1385
return ;
1397
1386
}
1398
1387
element . set ( CommonFlags . MODULE_EXPORT ) ;
1399
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
1400
- element,
1401
- identifier : declaration . name
1402
- } ) ;
1388
+ this . moduleLevelExports . set ( simpleName , element ) ;
1403
1389
}
1404
1390
}
1405
1391
@@ -1484,10 +1470,7 @@ export class Program extends DiagnosticEmitter {
1484
1470
1485
1471
// add module level export if a top-level export of an entry file
1486
1472
} else if ( source . isEntry ) {
1487
- this . moduleLevelExports . set ( externalIdentifier . text , < ModuleExport > {
1488
- element,
1489
- identifier : externalIdentifier
1490
- } ) ;
1473
+ this . moduleLevelExports . set ( externalIdentifier . text , element ) ;
1491
1474
}
1492
1475
}
1493
1476
@@ -1657,18 +1640,15 @@ export class Program extends DiagnosticEmitter {
1657
1640
this . currentFilespace . members . set ( simpleName , prototype ) ;
1658
1641
if ( declaration . range . source . isEntry ) {
1659
1642
if ( this . moduleLevelExports . has ( simpleName ) ) {
1660
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
1643
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
1661
1644
this . error (
1662
1645
DiagnosticCode . Duplicate_identifier_0 ,
1663
- declaration . name . range , existingExport . element . internalName
1646
+ declaration . name . range , existingExport . internalName
1664
1647
) ;
1665
1648
return ;
1666
1649
}
1667
1650
prototype . set ( CommonFlags . MODULE_EXPORT ) ;
1668
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
1669
- element : prototype ,
1670
- identifier : declaration . name
1671
- } ) ;
1651
+ this . moduleLevelExports . set ( simpleName , prototype ) ;
1672
1652
}
1673
1653
}
1674
1654
@@ -1822,18 +1802,15 @@ export class Program extends DiagnosticEmitter {
1822
1802
this . currentFilespace . members . set ( simpleName , prototype ) ;
1823
1803
if ( declaration . range . source . isEntry ) {
1824
1804
if ( this . moduleLevelExports . has ( simpleName ) ) {
1825
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
1805
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
1826
1806
this . error (
1827
1807
DiagnosticCode . Duplicate_identifier_0 ,
1828
- declaration . name . range , existingExport . element . internalName
1808
+ declaration . name . range , existingExport . internalName
1829
1809
) ;
1830
1810
return ;
1831
1811
}
1832
1812
prototype . set ( CommonFlags . MODULE_EXPORT ) ;
1833
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
1834
- element : prototype ,
1835
- identifier : declaration . name
1836
- } ) ;
1813
+ this . moduleLevelExports . set ( simpleName , prototype ) ;
1837
1814
}
1838
1815
}
1839
1816
@@ -1911,19 +1888,16 @@ export class Program extends DiagnosticEmitter {
1911
1888
this . currentFilespace . members . set ( simpleName , namespace ) ;
1912
1889
if ( declaration . range . source . isEntry ) {
1913
1890
if ( this . moduleLevelExports . has ( simpleName ) ) {
1914
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
1915
- if ( existingExport . element !== namespace ) { // not merged
1891
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
1892
+ if ( existingExport !== namespace ) { // not merged
1916
1893
this . error (
1917
1894
DiagnosticCode . Duplicate_identifier_0 ,
1918
- declaration . name . range , existingExport . element . internalName
1895
+ declaration . name . range , existingExport . internalName
1919
1896
) ;
1920
1897
return ;
1921
1898
}
1922
1899
} else {
1923
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
1924
- element : namespace ,
1925
- identifier : declaration . name
1926
- } ) ;
1900
+ this . moduleLevelExports . set ( simpleName , namespace ) ;
1927
1901
}
1928
1902
namespace . set ( CommonFlags . MODULE_EXPORT ) ;
1929
1903
}
@@ -2055,18 +2029,15 @@ export class Program extends DiagnosticEmitter {
2055
2029
this . currentFilespace . members . set ( simpleName , global ) ;
2056
2030
if ( declaration . range . source . isEntry ) {
2057
2031
if ( this . moduleLevelExports . has ( simpleName ) ) {
2058
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
2032
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
2059
2033
this . error (
2060
2034
DiagnosticCode . Duplicate_identifier_0 ,
2061
- declaration . name . range , existingExport . element . internalName
2035
+ declaration . name . range , existingExport . internalName
2062
2036
) ;
2063
2037
continue ;
2064
2038
}
2065
2039
global . set ( CommonFlags . MODULE_EXPORT ) ;
2066
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
2067
- element : global ,
2068
- identifier : declaration . name
2069
- } ) ;
2040
+ this . moduleLevelExports . set ( simpleName , global ) ;
2070
2041
}
2071
2042
}
2072
2043
this . checkGlobal ( global , declaration ) ;
0 commit comments