@@ -285,8 +285,8 @@ export class Compiler extends DiagnosticEmitter {
285285 currentFlow : Flow ;
286286 /** Current inline functions stack. */
287287 currentInlineFunctions : Function [ ] = [ ] ;
288- /** Current enum in compilation . */
289- currentEnum : Enum | null = null ;
288+ /** Current parent element if not a function, i.e. an enum or namespace . */
289+ currentParent : Element | null = null ;
290290 /** Current type in compilation. */
291291 currentType : Type = Type . void ;
292292 /** Start function statements. */
@@ -987,7 +987,8 @@ export class Compiler extends DiagnosticEmitter {
987987 element . set ( CommonFlags . COMPILED ) ;
988988
989989 var module = this . module ;
990- this . currentEnum = element ;
990+ var previousParent = this . currentParent ;
991+ this . currentParent = element ;
991992 var previousValue : EnumValue | null = null ;
992993 var previousValueIsMut = false ;
993994 var isInline = element . is ( CommonFlags . CONST ) || element . hasDecorator ( DecoratorFlags . INLINE ) ;
@@ -1066,7 +1067,7 @@ export class Compiler extends DiagnosticEmitter {
10661067 previousValue = < EnumValue > val ;
10671068 }
10681069 }
1069- this . currentEnum = null ;
1070+ this . currentParent = previousParent ;
10701071 return true ;
10711072 }
10721073
@@ -1622,9 +1623,6 @@ export class Compiler extends DiagnosticEmitter {
16221623 // === Statements ===============================================================================
16231624
16241625 compileTopLevelStatement ( statement : Statement , body : ExpressionRef [ ] ) : void {
1625- if ( statement . kind == NodeKind . EXPORTDEFAULT ) {
1626- statement = ( < ExportDefaultStatement > statement ) . declaration ;
1627- }
16281626 switch ( statement . kind ) {
16291627 case NodeKind . CLASSDECLARATION : {
16301628 let memberStatements = ( < ClassDeclaration > statement ) . members ;
@@ -1642,9 +1640,16 @@ export class Compiler extends DiagnosticEmitter {
16421640 break ;
16431641 }
16441642 case NodeKind . NAMESPACEDECLARATION : {
1645- let memberStatements = ( < NamespaceDeclaration > statement ) . members ;
1646- for ( let i = 0 , k = memberStatements . length ; i < k ; ++ i ) {
1647- this . compileTopLevelStatement ( memberStatements [ i ] , body ) ;
1643+ let element = this . program . getElementByDeclaration ( < NamespaceDeclaration > statement ) ;
1644+ if ( element ) {
1645+ // any potentiall merged element
1646+ let previousParent = this . currentParent ;
1647+ this . currentParent = element ;
1648+ let memberStatements = ( < NamespaceDeclaration > statement ) . members ;
1649+ for ( let i = 0 , k = memberStatements . length ; i < k ; ++ i ) {
1650+ this . compileTopLevelStatement ( memberStatements [ i ] , body ) ;
1651+ }
1652+ this . currentParent = previousParent ;
16481653 }
16491654 break ;
16501655 }
@@ -1678,6 +1683,10 @@ export class Compiler extends DiagnosticEmitter {
16781683 }
16791684 break ;
16801685 }
1686+ case NodeKind . EXPORTDEFAULT : {
1687+ this . compileTopLevelStatement ( ( < ExportDefaultStatement > statement ) . declaration , body ) ;
1688+ break ;
1689+ }
16811690 case NodeKind . IMPORT : {
16821691 this . compileFileByPath (
16831692 ( < ImportStatement > statement ) . internalPath ,
@@ -7209,7 +7218,7 @@ export class Compiler extends DiagnosticEmitter {
72097218 var target = this . resolver . lookupIdentifierExpression ( // reports
72107219 expression ,
72117220 flow ,
7212- this . currentEnum || actualFunction
7221+ this . currentParent || actualFunction
72137222 ) ;
72147223 if ( ! target ) return module . unreachable ( ) ;
72157224
0 commit comments