@@ -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,14 +642,14 @@ 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 ;
645
+ let mainElement = this . moduleLevelExports . get ( "main" ) ;
646
+ if ( mainElement ) {
653
647
if (
654
- element . kind == ElementKind . FUNCTION_PROTOTYPE &&
655
- ! ( < FunctionPrototype > element ) . isAny ( CommonFlags . GENERIC | CommonFlags . AMBIENT )
648
+ mainElement . kind == ElementKind . FUNCTION_PROTOTYPE &&
649
+ ! ( < FunctionPrototype > mainElement ) . isAny ( CommonFlags . GENERIC | CommonFlags . AMBIENT )
656
650
) {
657
- ( < FunctionPrototype > element ) . set ( CommonFlags . MAIN ) ;
658
- this . mainFunction = < FunctionPrototype > element ;
651
+ ( < FunctionPrototype > mainElement ) . set ( CommonFlags . MAIN ) ;
652
+ this . mainFunction = < FunctionPrototype > mainElement ;
659
653
}
660
654
}
661
655
@@ -932,18 +926,15 @@ export class Program extends DiagnosticEmitter {
932
926
this . currentFilespace . members . set ( simpleName , prototype ) ;
933
927
if ( prototype . is ( CommonFlags . EXPORT ) && declaration . range . source . isEntry ) {
934
928
if ( this . moduleLevelExports . has ( simpleName ) ) {
935
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
929
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
936
930
this . error (
937
931
DiagnosticCode . Export_declaration_conflicts_with_exported_declaration_of_0 ,
938
- declaration . name . range , existingExport . element . internalName
932
+ declaration . name . range , existingExport . internalName
939
933
) ;
940
934
return ;
941
935
}
942
936
prototype . set ( CommonFlags . MODULE_EXPORT ) ;
943
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
944
- element : prototype ,
945
- identifier : declaration . name
946
- } ) ;
937
+ this . moduleLevelExports . set ( simpleName , prototype ) ;
947
938
}
948
939
}
949
940
@@ -1388,18 +1379,15 @@ export class Program extends DiagnosticEmitter {
1388
1379
this . currentFilespace . members . set ( simpleName , element ) ;
1389
1380
if ( declaration . range . source . isEntry ) {
1390
1381
if ( this . moduleLevelExports . has ( simpleName ) ) {
1391
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
1382
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
1392
1383
this . error (
1393
1384
DiagnosticCode . Export_declaration_conflicts_with_exported_declaration_of_0 ,
1394
- declaration . name . range , existingExport . element . internalName
1385
+ declaration . name . range , existingExport . internalName
1395
1386
) ;
1396
1387
return ;
1397
1388
}
1398
1389
element . set ( CommonFlags . MODULE_EXPORT ) ;
1399
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
1400
- element,
1401
- identifier : declaration . name
1402
- } ) ;
1390
+ this . moduleLevelExports . set ( simpleName , element ) ;
1403
1391
}
1404
1392
}
1405
1393
@@ -1484,10 +1472,7 @@ export class Program extends DiagnosticEmitter {
1484
1472
1485
1473
// add module level export if a top-level export of an entry file
1486
1474
} else if ( source . isEntry ) {
1487
- this . moduleLevelExports . set ( externalIdentifier . text , < ModuleExport > {
1488
- element,
1489
- identifier : externalIdentifier
1490
- } ) ;
1475
+ this . moduleLevelExports . set ( externalIdentifier . text , element ) ;
1491
1476
}
1492
1477
}
1493
1478
@@ -1657,18 +1642,15 @@ export class Program extends DiagnosticEmitter {
1657
1642
this . currentFilespace . members . set ( simpleName , prototype ) ;
1658
1643
if ( declaration . range . source . isEntry ) {
1659
1644
if ( this . moduleLevelExports . has ( simpleName ) ) {
1660
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
1645
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
1661
1646
this . error (
1662
1647
DiagnosticCode . Duplicate_identifier_0 ,
1663
- declaration . name . range , existingExport . element . internalName
1648
+ declaration . name . range , existingExport . internalName
1664
1649
) ;
1665
1650
return ;
1666
1651
}
1667
1652
prototype . set ( CommonFlags . MODULE_EXPORT ) ;
1668
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
1669
- element : prototype ,
1670
- identifier : declaration . name
1671
- } ) ;
1653
+ this . moduleLevelExports . set ( simpleName , prototype ) ;
1672
1654
}
1673
1655
}
1674
1656
@@ -1822,18 +1804,15 @@ export class Program extends DiagnosticEmitter {
1822
1804
this . currentFilespace . members . set ( simpleName , prototype ) ;
1823
1805
if ( declaration . range . source . isEntry ) {
1824
1806
if ( this . moduleLevelExports . has ( simpleName ) ) {
1825
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
1807
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
1826
1808
this . error (
1827
1809
DiagnosticCode . Duplicate_identifier_0 ,
1828
- declaration . name . range , existingExport . element . internalName
1810
+ declaration . name . range , existingExport . internalName
1829
1811
) ;
1830
1812
return ;
1831
1813
}
1832
1814
prototype . set ( CommonFlags . MODULE_EXPORT ) ;
1833
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
1834
- element : prototype ,
1835
- identifier : declaration . name
1836
- } ) ;
1815
+ this . moduleLevelExports . set ( simpleName , prototype ) ;
1837
1816
}
1838
1817
}
1839
1818
@@ -1911,19 +1890,16 @@ export class Program extends DiagnosticEmitter {
1911
1890
this . currentFilespace . members . set ( simpleName , namespace ) ;
1912
1891
if ( declaration . range . source . isEntry ) {
1913
1892
if ( this . moduleLevelExports . has ( simpleName ) ) {
1914
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
1915
- if ( existingExport . element !== namespace ) { // not merged
1893
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
1894
+ if ( existingExport !== namespace ) { // not merged
1916
1895
this . error (
1917
1896
DiagnosticCode . Duplicate_identifier_0 ,
1918
- declaration . name . range , existingExport . element . internalName
1897
+ declaration . name . range , existingExport . internalName
1919
1898
) ;
1920
1899
return ;
1921
1900
}
1922
1901
} else {
1923
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
1924
- element : namespace ,
1925
- identifier : declaration . name
1926
- } ) ;
1902
+ this . moduleLevelExports . set ( simpleName , namespace ) ;
1927
1903
}
1928
1904
namespace . set ( CommonFlags . MODULE_EXPORT ) ;
1929
1905
}
@@ -2055,18 +2031,15 @@ export class Program extends DiagnosticEmitter {
2055
2031
this . currentFilespace . members . set ( simpleName , global ) ;
2056
2032
if ( declaration . range . source . isEntry ) {
2057
2033
if ( this . moduleLevelExports . has ( simpleName ) ) {
2058
- let existingExport = < ModuleExport > this . moduleLevelExports . get ( simpleName ) ;
2034
+ let existingExport = this . moduleLevelExports . get ( simpleName ) ! ;
2059
2035
this . error (
2060
2036
DiagnosticCode . Duplicate_identifier_0 ,
2061
- declaration . name . range , existingExport . element . internalName
2037
+ declaration . name . range , existingExport . internalName
2062
2038
) ;
2063
2039
continue ;
2064
2040
}
2065
2041
global . set ( CommonFlags . MODULE_EXPORT ) ;
2066
- this . moduleLevelExports . set ( simpleName , < ModuleExport > {
2067
- element : global ,
2068
- identifier : declaration . name
2069
- } ) ;
2042
+ this . moduleLevelExports . set ( simpleName , global ) ;
2070
2043
}
2071
2044
}
2072
2045
this . checkGlobal ( global , declaration ) ;
0 commit comments