@@ -1141,11 +1141,12 @@ export class Program extends DiagnosticEmitter {
11411141 let queuedImport = queuedImports [ i ] ;
11421142 let localIdentifier = queuedImport . localIdentifier ;
11431143 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 ) ) ;
11441146 if ( foreignIdentifier ) { // i.e. import { foo [as bar] } from "./baz"
11451147 let element = this . lookupForeign (
11461148 foreignIdentifier . text ,
1147- queuedImport . foreignPath ,
1148- queuedImport . foreignPathAlt ,
1149+ foreignFile ,
11491150 queuedExports
11501151 ) ;
11511152 if ( element ) {
@@ -1160,25 +1161,19 @@ export class Program extends DiagnosticEmitter {
11601161 ++ i ;
11611162 }
11621163 } 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 (
11681169 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 ;
11821177 }
11831178 }
11841179 if ( ! madeProgress ) {
@@ -1209,12 +1204,9 @@ export class Program extends DiagnosticEmitter {
12091204 let localName = queuedExport . localIdentifier . text ;
12101205 let foreignPath = queuedExport . foreignPath ;
12111206 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 ) ;
12181210 if ( element ) {
12191211 file . ensureExport ( exportName , element ) ;
12201212 } else {
@@ -1725,40 +1717,48 @@ export class Program extends DiagnosticEmitter {
17251717 private lookupForeign (
17261718 /** Identifier within the other file. */
17271719 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 ,
17321722 /** So far queued exports. */
17331723 queuedExports : Map < File , Map < string , QueuedExport > >
17341724 ) : DeclaredElement | null {
17351725 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
17401727 let element = foreignFile . lookupExport ( foreignName ) ;
17411728 if ( element ) return element ;
17421729
1743- // otherwise traverse queued exports
1730+ // follow queued exports
17441731 if ( queuedExports . has ( foreignFile ) ) {
17451732 let fileQueuedExports = assert ( queuedExports . get ( foreignFile ) ) ;
17461733 if ( fileQueuedExports . has ( foreignName ) ) {
17471734 let queuedExport = assert ( fileQueuedExports . get ( foreignName ) ) ;
17481735 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 ;
17501741 foreignName = queuedExport . localIdentifier . text ;
1751- foreignPath = queuedExportForeignPath ;
1752- foreignPathAlt = assert ( queuedExport . foreignPathAlt ) ;
1742+ foreignFile = otherFile ;
17531743 continue ;
1754- } else { // local element of this file
1755- element = foreignFile . lookupInSelf ( queuedExport . localIdentifier . text ) ;
1756- if ( element ) return element ;
17571744 }
1745+
1746+ // exported from this file
1747+ element = foreignFile . lookupInSelf ( queuedExport . localIdentifier . text ) ;
1748+ if ( element ) return element ;
17581749 }
17591750 }
17601751 break ;
17611752 } 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+ }
17621762 return null ;
17631763 }
17641764
@@ -2334,10 +2334,13 @@ export class Program extends DiagnosticEmitter {
23342334 : foreignPath + INDEX_SUFFIX ;
23352335
23362336 // 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+ }
23412344 }
23422345
23432346 // otherwise queue it
0 commit comments