@@ -1053,7 +1053,7 @@ export class Program extends DiagnosticEmitter {
1053
1053
let localName = localIdentifier . text ;
1054
1054
localFile . add (
1055
1055
localName ,
1056
- foreignFile . asImportedNamespace (
1056
+ foreignFile . asAliasNamespace (
1057
1057
localName ,
1058
1058
localFile ,
1059
1059
localIdentifier
@@ -2893,6 +2893,8 @@ export class File extends Element {
2893
2893
exportsStar : File [ ] | null = null ;
2894
2894
/** Top-level start function of this file. */
2895
2895
startFunction ! : Function ;
2896
+ /** Array of `import * as X` alias namespaces of this file. */
2897
+ aliasNamespaces : Array < Namespace > = new Array < Namespace > ( ) ;
2896
2898
2897
2899
/** Constructs a new file. */
2898
2900
constructor (
@@ -2962,6 +2964,12 @@ export class File extends Element {
2962
2964
if ( ! exports ) this . exports = exports = new Map ( ) ;
2963
2965
exports . set ( name , element ) ;
2964
2966
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
+ }
2965
2973
}
2966
2974
2967
2975
/** Ensures that another file is a re-export of this file. */
@@ -2987,12 +2995,20 @@ export class File extends Element {
2987
2995
}
2988
2996
2989
2997
/** 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 {
2991
3003
var declaration = this . program . makeNativeNamespaceDeclaration ( name ) ;
2992
3004
declaration . name = localIdentifier ;
2993
3005
var ns = new Namespace ( name , parent , declaration ) ;
2994
3006
ns . set ( CommonFlags . SCOPED ) ;
2995
3007
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 ) ;
2996
3012
return ns ;
2997
3013
}
2998
3014
0 commit comments