@@ -122,9 +122,14 @@ export class AotPlugin implements Tapable {
122122 const configResult = ts . readConfigFile ( this . _tsConfigPath , ts . sys . readFile ) ;
123123 if ( configResult . error ) {
124124 const diagnostic = configResult . error ;
125- const { line, character} = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start ) ;
126125 const message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
127- throw new Error ( `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } )` ) ;
126+
127+ if ( diagnostic . file ) {
128+ const { line, character} = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start ) ;
129+ throw new Error ( `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } )` ) ;
130+ } else {
131+ throw new Error ( message ) ;
132+ }
128133 }
129134
130135 const tsConfigJson = configResult . config ;
@@ -422,14 +427,20 @@ export class AotPlugin implements Tapable {
422427
423428 if ( diagnostics . length > 0 ) {
424429 diagnostics . forEach ( diagnostic => {
425- const position = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start ) ;
430+ const messageText = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
431+ let message ;
426432
427- const sourceText = diagnostic . file . getFullText ( ) ;
428- let { line, character, fileName} = this . _translateSourceMap ( sourceText ,
429- diagnostic . file . fileName , position ) ;
433+ if ( diagnostic . file ) {
434+ const position = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start ) ;
430435
431- const messageText = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
432- const message = `${ fileName } (${ line + 1 } ,${ character + 1 } ): ${ messageText } ` ;
436+ const sourceText = diagnostic . file . getFullText ( ) ;
437+ let { line, character, fileName} = this . _translateSourceMap ( sourceText ,
438+ diagnostic . file . fileName , position ) ;
439+
440+ message = `${ fileName } (${ line + 1 } ,${ character + 1 } ): ${ messageText } ` ;
441+ } else {
442+ message = messageText ;
443+ }
433444
434445 switch ( diagnostic . category ) {
435446 case ts . DiagnosticCategory . Error :
@@ -501,10 +512,15 @@ export class AotPlugin implements Tapable {
501512 if ( diagnostics . length > 0 ) {
502513 const message = diagnostics
503514 . map ( diagnostic => {
504- const { line, character} = diagnostic . file . getLineAndCharacterOfPosition (
505- diagnostic . start ) ;
506515 const message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
507- return `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } )` ;
516+
517+ if ( diagnostic . file ) {
518+ const { line, character} = diagnostic . file . getLineAndCharacterOfPosition (
519+ diagnostic . start ) ;
520+ return `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } )` ;
521+ } else {
522+ return message ;
523+ }
508524 } )
509525 . join ( '\n' ) ;
510526
0 commit comments