@@ -341,11 +341,11 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
341
341
// We either load from memory or from disk
342
342
fileName = path . normalize ( fileName ) ;
343
343
var file = files [ fileName ] ;
344
-
344
+
345
345
if ( ! file ) {
346
346
let text = readFile ( fileName ) ;
347
347
if ( text == null ) return ;
348
-
348
+
349
349
file = files [ fileName ] = { version : 0 , text }
350
350
}
351
351
@@ -465,7 +465,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
465
465
pushArray ( compilation . errors , formatErrors ( errors , instance , { file : filePath } ) ) ;
466
466
}
467
467
} ) ;
468
-
468
+
469
469
callback ( ) ;
470
470
} ) ;
471
471
@@ -526,13 +526,13 @@ function loader(contents) {
526
526
if ( ! file ) {
527
527
file = instance . files [ filePath ] = < TSFile > { version : 0 } ;
528
528
}
529
-
529
+
530
530
if ( file . text !== contents ) {
531
531
file . version ++ ;
532
532
file . text = contents ;
533
533
instance . version ++ ;
534
534
}
535
-
535
+
536
536
var outputText : string , sourceMapText : string , diagnostics : typescript . Diagnostic [ ] = [ ] ;
537
537
538
538
if ( options . transpileOnly ) {
@@ -549,11 +549,11 @@ function loader(contents) {
549
549
}
550
550
else {
551
551
let langService = instance . languageService ;
552
-
552
+
553
553
// Make this file dependent on *all* definition files in the program
554
554
this . clearDependencies ( ) ;
555
555
this . addDependency ( filePath ) ;
556
-
556
+
557
557
let allDefinitionFiles = Object . keys ( instance . files ) . filter ( filePath => / \. d \. t s $ / . test ( filePath ) ) ;
558
558
allDefinitionFiles . forEach ( this . addDependency . bind ( this ) ) ;
559
559
this . _module . meta . tsLoaderDefinitionFileVersions = allDefinitionFiles . map ( filePath => filePath + '@' + instance . files [ filePath ] . version ) ;
@@ -566,9 +566,15 @@ function loader(contents) {
566
566
567
567
var sourceMapFile = output . outputFiles . filter ( file => ! ! file . name . match ( / \. j s ( x ? ) \. m a p $ / ) ) . pop ( ) ;
568
568
if ( sourceMapFile ) { sourceMapText = sourceMapFile . text }
569
-
569
+
570
570
var declarationFile = output . outputFiles . filter ( file => ! ! file . name . match ( / \. d .t s $ / ) ) . pop ( ) ;
571
571
if ( declarationFile ) { this . emitFile ( path . relative ( this . options . context , declarationFile . name ) , declarationFile . text ) ; }
572
+
573
+ // collect errors
574
+ diagnostics = diagnostics
575
+ . concat ( langService . getSyntacticDiagnostics ( filePath ) )
576
+ . concat ( langService . getSemanticDiagnostics ( filePath ) )
577
+ . concat ( langService . getCompilerOptionsDiagnostics ( ) ) ;
572
578
}
573
579
574
580
if ( outputText == null ) throw new Error ( `Typescript emitted no output for ${ filePath } ` ) ;
@@ -586,7 +592,15 @@ function loader(contents) {
586
592
// treated as new
587
593
this . _module . meta . tsLoaderFileVersion = file . version ;
588
594
589
- callback ( null , outputText , sourceMap )
595
+ var errorDiagnostics = diagnostics . filter ( d => d . category == typescript . DiagnosticCategory . Error ) ,
596
+ err = errorDiagnostics . length > 0
597
+ ? errorDiagnostics . map ( d => `ERROR in ${ d . file . fileName } \n(${ d . start } , ${ d . length } ): error TS${ d . code } : ${ d . messageText } ` )
598
+ : null ;
599
+ if ( err && err . length > 0 ) {
600
+ console . error ( 'ts-loader detected following errors:' ) ;
601
+ err . forEach ( ( e , i ) => console . error ( ` ${ i + 1 } )` , e . replace ( '\n' , '\n ' ) , "\n" ) ) ;
602
+ }
603
+ callback ( err , outputText , sourceMap )
590
604
}
591
605
592
606
export = loader ;
0 commit comments