@@ -1141,11 +1141,12 @@ export class Program extends DiagnosticEmitter {
1141
1141
let queuedImport = queuedImports [ i ] ;
1142
1142
let localIdentifier = queuedImport . localIdentifier ;
1143
1143
let foreignIdentifier = queuedImport . foreignIdentifier ;
1144
+ // File must be found here, as it would otherwise already have been reported by the parser
1145
+ let foreignFile = assert ( this . lookupForeignFile ( queuedImport . foreignPath , queuedImport . foreignPathAlt ) ) ;
1144
1146
if ( foreignIdentifier ) { // i.e. import { foo [as bar] } from "./baz"
1145
1147
let element = this . lookupForeign (
1146
1148
foreignIdentifier . text ,
1147
- queuedImport . foreignPath ,
1148
- queuedImport . foreignPathAlt ,
1149
+ foreignFile ,
1149
1150
queuedExports
1150
1151
) ;
1151
1152
if ( element ) {
@@ -1160,25 +1161,19 @@ export class Program extends DiagnosticEmitter {
1160
1161
++ i ;
1161
1162
}
1162
1163
} else { // i.e. import * as bar from "./bar"
1163
- let foreignFile = this . lookupForeignFile ( queuedImport . foreignPath , queuedImport . foreignPathAlt ) ;
1164
- if ( foreignFile ) {
1165
- let localFile = queuedImport . localFile ;
1166
- let localName = localIdentifier . text ;
1167
- localFile . add (
1164
+ let localFile = queuedImport . localFile ;
1165
+ let localName = localIdentifier . text ;
1166
+ localFile . add (
1167
+ localName ,
1168
+ foreignFile . asAliasNamespace (
1168
1169
localName ,
1169
- foreignFile . asAliasNamespace (
1170
- localName ,
1171
- localFile ,
1172
- localIdentifier
1173
- ) ,
1174
- localIdentifier // isImport
1175
- ) ;
1176
- queuedImports . splice ( i , 1 ) ;
1177
- madeProgress = true ;
1178
- } else {
1179
- ++ i ;
1180
- assert ( false ) ; // already reported by the parser not finding the file
1181
- }
1170
+ localFile ,
1171
+ localIdentifier
1172
+ ) ,
1173
+ localIdentifier // isImport
1174
+ ) ;
1175
+ queuedImports . splice ( i , 1 ) ;
1176
+ madeProgress = true ;
1182
1177
}
1183
1178
}
1184
1179
if ( ! madeProgress ) {
@@ -1209,12 +1204,9 @@ export class Program extends DiagnosticEmitter {
1209
1204
let localName = queuedExport . localIdentifier . text ;
1210
1205
let foreignPath = queuedExport . foreignPath ;
1211
1206
if ( foreignPath ) { // i.e. export { foo [as bar] } from "./baz"
1212
- let element = this . lookupForeign (
1213
- localName ,
1214
- foreignPath ,
1215
- assert ( queuedExport . foreignPathAlt ) , // must be set if foreignPath is
1216
- queuedExports
1217
- ) ;
1207
+ // File must be found here, as it would otherwise already have been reported by the parser
1208
+ let foreignFile = assert ( this . lookupForeignFile ( foreignPath , assert ( queuedExport . foreignPathAlt ) ) ) ;
1209
+ let element = this . lookupForeign ( localName , foreignFile , queuedExports ) ;
1218
1210
if ( element ) {
1219
1211
file . ensureExport ( exportName , element ) ;
1220
1212
} else {
@@ -1725,40 +1717,48 @@ export class Program extends DiagnosticEmitter {
1725
1717
private lookupForeign (
1726
1718
/** Identifier within the other file. */
1727
1719
foreignName : string ,
1728
- /** Normalized path to the other file. */
1729
- foreignPath : string ,
1730
- /** Alternative normalized path to the other file. */
1731
- foreignPathAlt : string ,
1720
+ /** The other file. */
1721
+ foreignFile : File ,
1732
1722
/** So far queued exports. */
1733
1723
queuedExports : Map < File , Map < string , QueuedExport > >
1734
1724
) : DeclaredElement | null {
1735
1725
do {
1736
- let foreignFile = this . lookupForeignFile ( foreignPath , foreignPathAlt ) ;
1737
- if ( ! foreignFile ) return null ; // no such file
1738
-
1739
- // search already resolved exports
1726
+ // check if already resolved
1740
1727
let element = foreignFile . lookupExport ( foreignName ) ;
1741
1728
if ( element ) return element ;
1742
1729
1743
- // otherwise traverse queued exports
1730
+ // follow queued exports
1744
1731
if ( queuedExports . has ( foreignFile ) ) {
1745
1732
let fileQueuedExports = assert ( queuedExports . get ( foreignFile ) ) ;
1746
1733
if ( fileQueuedExports . has ( foreignName ) ) {
1747
1734
let queuedExport = assert ( fileQueuedExports . get ( foreignName ) ) ;
1748
1735
let queuedExportForeignPath = queuedExport . foreignPath ;
1749
- if ( queuedExportForeignPath ) { // imported from another file
1736
+
1737
+ // re-exported from another file
1738
+ if ( queuedExportForeignPath ) {
1739
+ let otherFile = this . lookupForeignFile ( queuedExportForeignPath , assert ( queuedExport . foreignPathAlt ) ) ;
1740
+ if ( ! otherFile ) return null ;
1750
1741
foreignName = queuedExport . localIdentifier . text ;
1751
- foreignPath = queuedExportForeignPath ;
1752
- foreignPathAlt = assert ( queuedExport . foreignPathAlt ) ;
1742
+ foreignFile = otherFile ;
1753
1743
continue ;
1754
- } else { // local element of this file
1755
- element = foreignFile . lookupInSelf ( queuedExport . localIdentifier . text ) ;
1756
- if ( element ) return element ;
1757
1744
}
1745
+
1746
+ // exported from this file
1747
+ element = foreignFile . lookupInSelf ( queuedExport . localIdentifier . text ) ;
1748
+ if ( element ) return element ;
1758
1749
}
1759
1750
}
1760
1751
break ;
1761
1752
} while ( true ) ;
1753
+
1754
+ // follow star exports
1755
+ var exportsStar = foreignFile . exportsStar ;
1756
+ if ( exportsStar ) {
1757
+ for ( let i = 0 , k = exportsStar . length ; i < k ; ++ i ) {
1758
+ let element = this . lookupForeign ( foreignName , exportsStar [ i ] , queuedExports ) ;
1759
+ if ( element ) return element ;
1760
+ }
1761
+ }
1762
1762
return null ;
1763
1763
}
1764
1764
@@ -2334,10 +2334,13 @@ export class Program extends DiagnosticEmitter {
2334
2334
: foreignPath + INDEX_SUFFIX ;
2335
2335
2336
2336
// resolve right away if the element exists
2337
- var element = this . lookupForeign ( declaration . foreignName . text , foreignPath , foreignPathAlt , queuedExports ) ;
2338
- if ( element ) {
2339
- parent . add ( declaration . name . text , element , declaration . name /* isImport */ ) ;
2340
- return ;
2337
+ var foreignFile = this . lookupForeignFile ( foreignPath , foreignPathAlt ) ;
2338
+ if ( foreignFile ) {
2339
+ var element = this . lookupForeign ( declaration . foreignName . text , foreignFile , queuedExports ) ;
2340
+ if ( element ) {
2341
+ parent . add ( declaration . name . text , element , declaration . name /* isImport */ ) ;
2342
+ return ;
2343
+ }
2341
2344
}
2342
2345
2343
2346
// otherwise queue it
0 commit comments