@@ -89,6 +89,14 @@ import {
8989 mangleInternalPath
9090} from "./ast" ;
9191
92+ /** Represents a dependee. */
93+ class Dependee {
94+ constructor (
95+ public source : Source ,
96+ public reportNode : Node
97+ ) { }
98+ }
99+
92100/** Parser interface. */
93101export class Parser extends DiagnosticEmitter {
94102
@@ -102,8 +110,8 @@ export class Parser extends DiagnosticEmitter {
102110 onComment : CommentHandler | null = null ;
103111 /** Current file being parsed. */
104112 currentSource : Source | null = null ;
105- /** Dependency map * */
106- dependees : Map < string , Source > = new Map ( ) ;
113+ /** Map of dependees being depended upon by a source, by path. */
114+ dependees : Map < string , Dependee > = new Map ( ) ;
107115 /** An array of parsed sources. */
108116 sources : Source [ ] ;
109117
@@ -118,21 +126,37 @@ export class Parser extends DiagnosticEmitter {
118126
119127 /** Parses a file and adds its definitions to the program. */
120128 parseFile (
121- /** Source text of the file. */
122- text : string ,
129+ /** Source text of the file, or `null` to indicate not found . */
130+ text : string | null ,
123131 /** Normalized path of the file. */
124132 path : string ,
125133 /** Whether this is an entry file. */
126134 isEntry : bool
127135 ) : void {
128136 // the frontend gives us paths with file extensions
129137 var normalizedPath = normalizePath ( path ) ;
130- var internalPath = mangleInternalPath ( normalizedPath ) ;
138+ var internalPath = mangleInternalPath ( path ) ;
139+
131140 // check if already processed
132141 if ( this . donelog . has ( internalPath ) ) return ;
133142 this . donelog . add ( internalPath ) ; // do not parse again
134143 this . seenlog . add ( internalPath ) ; // do not request again
135144
145+ // check if this is an error
146+ if ( text === null ) {
147+ let dependees = this . dependees ;
148+ let dependee : Dependee | null = null ;
149+ if ( dependees . has ( internalPath ) ) dependee = assert ( dependees . get ( internalPath ) ) ;
150+ this . error (
151+ DiagnosticCode . File_0_not_found ,
152+ dependee
153+ ? dependee . reportNode . range
154+ : null ,
155+ path
156+ ) ;
157+ return ;
158+ }
159+
136160 // create the source element
137161 var source = new Source (
138162 isEntry
@@ -402,10 +426,13 @@ export class Parser extends DiagnosticEmitter {
402426 return backlog . length ? assert ( backlog . shift ( ) ) : null ;
403427 }
404428
405- /** Obtains the dependee of the given imported file. */
429+ /** Obtains the path of the dependee of the given imported file. */
406430 getDependee ( dependent : string ) : string | null {
407- var source = this . dependees . get ( dependent ) ;
408- if ( source ) return source . internalPath ;
431+ var dependees = this . dependees ;
432+ if ( dependees . has ( dependent ) ) {
433+ let dependee = assert ( dependees . get ( dependent ) ) ;
434+ return dependee . source . internalPath ;
435+ }
409436 return null ;
410437 }
411438
@@ -2447,11 +2474,13 @@ export class Parser extends DiagnosticEmitter {
24472474 }
24482475 }
24492476 let ret = Node . createExportStatement ( members , path , isDeclare , tn . range ( startPos , tn . pos ) ) ;
2450- let internalPath = ret . internalPath ;
2451- if ( internalPath !== null && ! this . seenlog . has ( internalPath ) ) {
2452- this . dependees . set ( internalPath , currentSource ) ;
2453- this . backlog . push ( internalPath ) ;
2454- this . seenlog . add ( internalPath ) ;
2477+ if ( path !== null ) {
2478+ let internalPath = assert ( ret . internalPath ) ;
2479+ if ( ! this . seenlog . has ( internalPath ) ) {
2480+ this . dependees . set ( internalPath , new Dependee ( currentSource , path ) ) ;
2481+ this . backlog . push ( internalPath ) ;
2482+ this . seenlog . add ( internalPath ) ;
2483+ }
24552484 }
24562485 tn . skip ( Token . SEMICOLON ) ;
24572486 return ret ;
@@ -2466,7 +2495,7 @@ export class Parser extends DiagnosticEmitter {
24662495 if ( ! exportPaths ) source . exportPaths = [ internalPath ] ;
24672496 else if ( ! exportPaths . includes ( internalPath ) ) exportPaths . push ( internalPath ) ;
24682497 if ( ! this . seenlog . has ( internalPath ) ) {
2469- this . dependees . set ( internalPath , currentSource ) ;
2498+ this . dependees . set ( internalPath , new Dependee ( currentSource , path ) ) ;
24702499 this . backlog . push ( internalPath ) ;
24712500 }
24722501 tn . skip ( Token . SEMICOLON ) ;
@@ -2638,7 +2667,7 @@ export class Parser extends DiagnosticEmitter {
26382667 }
26392668 let internalPath = ret . internalPath ;
26402669 if ( ! this . seenlog . has ( internalPath ) ) {
2641- this . dependees . set ( internalPath , assert ( this . currentSource ) ) ;
2670+ this . dependees . set ( internalPath , new Dependee ( assert ( this . currentSource ) , path ) ) ;
26422671 this . backlog . push ( internalPath ) ;
26432672 }
26442673 tn . skip ( Token . SEMICOLON ) ;
0 commit comments