@@ -1053,7 +1053,7 @@ export class Program extends DiagnosticEmitter {
10531053 let localName = localIdentifier . text ;
10541054 localFile . add (
10551055 localName ,
1056- foreignFile . asImportedNamespace (
1056+ foreignFile . asAliasNamespace (
10571057 localName ,
10581058 localFile ,
10591059 localIdentifier
@@ -2893,6 +2893,8 @@ export class File extends Element {
28932893 exportsStar : File [ ] | null = null ;
28942894 /** Top-level start function of this file. */
28952895 startFunction ! : Function ;
2896+ /** Array of `import * as X` alias namespaces of this file. */
2897+ aliasNamespaces : Array < Namespace > = new Array < Namespace > ( ) ;
28962898
28972899 /** Constructs a new file. */
28982900 constructor (
@@ -2962,6 +2964,12 @@ export class File extends Element {
29622964 if ( ! exports ) this . exports = exports = new Map ( ) ;
29632965 exports . set ( name , element ) ;
29642966 if ( this . source . sourceKind == SourceKind . LIBRARY_ENTRY ) this . program . ensureGlobal ( name , element ) ;
2967+
2968+ // Also, add to the namespaces that capture our exports
2969+ for ( let i = 0 ; i < this . aliasNamespaces . length ; i ++ ) {
2970+ let ns = this . aliasNamespaces [ i ] ;
2971+ ns . add ( name , element ) ;
2972+ }
29652973 }
29662974
29672975 /** Ensures that another file is a re-export of this file. */
@@ -2987,12 +2995,20 @@ export class File extends Element {
29872995 }
29882996
29892997 /** Creates an imported namespace from this file. */
2990- asImportedNamespace ( name : string , parent : Element , localIdentifier : IdentifierExpression ) : Namespace {
2998+ asAliasNamespace (
2999+ name : string ,
3000+ parent : Element ,
3001+ localIdentifier : IdentifierExpression
3002+ ) : Namespace {
29913003 var declaration = this . program . makeNativeNamespaceDeclaration ( name ) ;
29923004 declaration . name = localIdentifier ;
29933005 var ns = new Namespace ( name , parent , declaration ) ;
29943006 ns . set ( CommonFlags . SCOPED ) ;
29953007 this . copyExportsToNamespace ( ns ) ;
3008+ // NOTE: Some exports are still queued, and can't yet be added here,
3009+ // so we remember all the alias namespaces and add to them as well
3010+ // when adding an element to the file.
3011+ this . aliasNamespaces . push ( ns ) ;
29963012 return ns ;
29973013 }
29983014
0 commit comments