@@ -358,7 +358,8 @@ namespace ts {
358
358
export function createProgram ( rootNames : string [ ] , options : CompilerOptions , host ?: CompilerHost , oldProgram ?: Program ) : Program {
359
359
let program : Program ;
360
360
let files : SourceFile [ ] = [ ] ;
361
- let diagnostics = createDiagnosticCollection ( ) ;
361
+ let fileProcessingDiagnostics = createDiagnosticCollection ( ) ;
362
+ let programDiagnostics = createDiagnosticCollection ( ) ;
362
363
363
364
let commonSourceDirectory : string ;
364
365
let diagnosticsProducingTypeChecker : TypeChecker ;
@@ -428,6 +429,7 @@ namespace ts {
428
429
getIdentifierCount : ( ) => getDiagnosticsProducingTypeChecker ( ) . getIdentifierCount ( ) ,
429
430
getSymbolCount : ( ) => getDiagnosticsProducingTypeChecker ( ) . getSymbolCount ( ) ,
430
431
getTypeCount : ( ) => getDiagnosticsProducingTypeChecker ( ) . getTypeCount ( ) ,
432
+ getFileProcessingDiagnostics : ( ) => fileProcessingDiagnostics
431
433
} ;
432
434
return program ;
433
435
@@ -460,6 +462,7 @@ namespace ts {
460
462
461
463
// check if program source files has changed in the way that can affect structure of the program
462
464
let newSourceFiles : SourceFile [ ] = [ ] ;
465
+ let modifiedSourceFiles : SourceFile [ ] = [ ] ;
463
466
for ( let oldSourceFile of oldProgram . getSourceFiles ( ) ) {
464
467
let newSourceFile = host . getSourceFile ( oldSourceFile . fileName , options . target ) ;
465
468
if ( ! newSourceFile ) {
@@ -499,6 +502,7 @@ namespace ts {
499
502
}
500
503
// pass the cache of module resolutions from the old source file
501
504
newSourceFile . resolvedModules = oldSourceFile . resolvedModules ;
505
+ modifiedSourceFiles . push ( newSourceFile ) ;
502
506
}
503
507
else {
504
508
// file has no changes - use it as is
@@ -515,7 +519,11 @@ namespace ts {
515
519
}
516
520
517
521
files = newSourceFiles ;
522
+ fileProcessingDiagnostics = oldProgram . getFileProcessingDiagnostics ( ) ;
518
523
524
+ for ( let modifiedFile of modifiedSourceFiles ) {
525
+ fileProcessingDiagnostics . reattachFileDiagnostics ( modifiedFile ) ;
526
+ }
519
527
oldProgram . structureIsReused = true ;
520
528
521
529
return true ;
@@ -645,9 +653,10 @@ namespace ts {
645
653
Debug . assert ( ! ! sourceFile . bindDiagnostics ) ;
646
654
let bindDiagnostics = sourceFile . bindDiagnostics ;
647
655
let checkDiagnostics = typeChecker . getDiagnostics ( sourceFile , cancellationToken ) ;
648
- let programDiagnostics = diagnostics . getDiagnostics ( sourceFile . fileName ) ;
656
+ let fileProcessingDiagnosticsInFile = fileProcessingDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
657
+ let programDiagnosticsInFile = programDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
649
658
650
- return bindDiagnostics . concat ( checkDiagnostics ) . concat ( programDiagnostics ) ;
659
+ return bindDiagnostics . concat ( checkDiagnostics ) . concat ( fileProcessingDiagnosticsInFile ) . concat ( programDiagnosticsInFile ) ;
651
660
} ) ;
652
661
}
653
662
@@ -664,7 +673,8 @@ namespace ts {
664
673
665
674
function getOptionsDiagnostics ( ) : Diagnostic [ ] {
666
675
let allDiagnostics : Diagnostic [ ] = [ ] ;
667
- addRange ( allDiagnostics , diagnostics . getGlobalDiagnostics ( ) ) ;
676
+ addRange ( allDiagnostics , fileProcessingDiagnostics . getGlobalDiagnostics ( ) )
677
+ addRange ( allDiagnostics , programDiagnostics . getGlobalDiagnostics ( ) ) ;
668
678
return sortAndDeduplicateDiagnostics ( allDiagnostics ) ;
669
679
}
670
680
@@ -772,10 +782,10 @@ namespace ts {
772
782
773
783
if ( diagnostic ) {
774
784
if ( refFile !== undefined && refEnd !== undefined && refPos !== undefined ) {
775
- diagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos , diagnostic , ...diagnosticArgument ) ) ;
785
+ fileProcessingDiagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos , diagnostic , ...diagnosticArgument ) ) ;
776
786
}
777
787
else {
778
- diagnostics . add ( createCompilerDiagnostic ( diagnostic , ...diagnosticArgument ) ) ;
788
+ fileProcessingDiagnostics . add ( createCompilerDiagnostic ( diagnostic , ...diagnosticArgument ) ) ;
779
789
}
780
790
}
781
791
}
@@ -797,11 +807,11 @@ namespace ts {
797
807
// We haven't looked for this file, do so now and cache result
798
808
let file = host . getSourceFile ( fileName , options . target , hostErrorMessage => {
799
809
if ( refFile !== undefined && refPos !== undefined && refEnd !== undefined ) {
800
- diagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
810
+ fileProcessingDiagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
801
811
Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
802
812
}
803
813
else {
804
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
814
+ fileProcessingDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
805
815
}
806
816
} ) ;
807
817
filesByName . set ( canonicalName , file ) ;
@@ -837,11 +847,11 @@ namespace ts {
837
847
let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath ( file . fileName , host . getCurrentDirectory ( ) ) : file . fileName ;
838
848
if ( canonicalName !== sourceFileName ) {
839
849
if ( refFile !== undefined && refPos !== undefined && refEnd !== undefined ) {
840
- diagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
850
+ fileProcessingDiagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
841
851
Diagnostics . File_name_0_differs_from_already_included_file_name_1_only_in_casing , fileName , sourceFileName ) ) ;
842
852
}
843
853
else {
844
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . File_name_0_differs_from_already_included_file_name_1_only_in_casing , fileName , sourceFileName ) ) ;
854
+ fileProcessingDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . File_name_0_differs_from_already_included_file_name_1_only_in_casing , fileName , sourceFileName ) ) ;
845
855
}
846
856
}
847
857
}
@@ -877,7 +887,7 @@ namespace ts {
877
887
return ;
878
888
879
889
function findModuleSourceFile ( fileName : string , nameLiteral : Expression ) {
880
- return findSourceFile ( fileName , /* isDefaultLib */ false , file , nameLiteral . pos , nameLiteral . end ) ;
890
+ return findSourceFile ( fileName , /* isDefaultLib */ false , file , skipTrivia ( file . text , nameLiteral . pos ) , nameLiteral . end ) ;
881
891
}
882
892
}
883
893
@@ -902,7 +912,7 @@ namespace ts {
902
912
for ( let i = 0 , n = Math . min ( commonPathComponents . length , sourcePathComponents . length ) ; i < n ; i ++ ) {
903
913
if ( commonPathComponents [ i ] !== sourcePathComponents [ i ] ) {
904
914
if ( i === 0 ) {
905
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_find_the_common_subdirectory_path_for_the_input_files ) ) ;
915
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_find_the_common_subdirectory_path_for_the_input_files ) ) ;
906
916
return ;
907
917
}
908
918
@@ -931,7 +941,7 @@ namespace ts {
931
941
if ( ! isDeclarationFile ( sourceFile ) ) {
932
942
let absoluteSourceFilePath = host . getCanonicalFileName ( getNormalizedAbsolutePath ( sourceFile . fileName , currentDirectory ) ) ;
933
943
if ( absoluteSourceFilePath . indexOf ( absoluteRootDirectoryPath ) !== 0 ) {
934
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files , sourceFile . fileName , options . rootDir ) ) ;
944
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files , sourceFile . fileName , options . rootDir ) ) ;
935
945
allFilesBelongToPath = false ;
936
946
}
937
947
}
@@ -944,52 +954,52 @@ namespace ts {
944
954
function verifyCompilerOptions ( ) {
945
955
if ( options . isolatedModules ) {
946
956
if ( options . declaration ) {
947
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "declaration" , "isolatedModules" ) ) ;
957
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "declaration" , "isolatedModules" ) ) ;
948
958
}
949
959
950
960
if ( options . noEmitOnError ) {
951
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmitOnError" , "isolatedModules" ) ) ;
961
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmitOnError" , "isolatedModules" ) ) ;
952
962
}
953
963
954
964
if ( options . out ) {
955
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "out" , "isolatedModules" ) ) ;
965
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "out" , "isolatedModules" ) ) ;
956
966
}
957
967
958
968
if ( options . outFile ) {
959
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "outFile" , "isolatedModules" ) ) ;
969
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "outFile" , "isolatedModules" ) ) ;
960
970
}
961
971
}
962
972
963
973
if ( options . inlineSourceMap ) {
964
974
if ( options . sourceMap ) {
965
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "sourceMap" , "inlineSourceMap" ) ) ;
975
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "sourceMap" , "inlineSourceMap" ) ) ;
966
976
}
967
977
if ( options . mapRoot ) {
968
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "mapRoot" , "inlineSourceMap" ) ) ;
978
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "mapRoot" , "inlineSourceMap" ) ) ;
969
979
}
970
980
if ( options . sourceRoot ) {
971
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "sourceRoot" , "inlineSourceMap" ) ) ;
981
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "sourceRoot" , "inlineSourceMap" ) ) ;
972
982
}
973
983
}
974
984
975
985
976
986
if ( options . inlineSources ) {
977
987
if ( ! options . sourceMap && ! options . inlineSourceMap ) {
978
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided ) ) ;
988
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided ) ) ;
979
989
}
980
990
}
981
991
982
992
if ( options . out && options . outFile ) {
983
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "out" , "outFile" ) ) ;
993
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "out" , "outFile" ) ) ;
984
994
}
985
995
986
996
if ( ! options . sourceMap && ( options . mapRoot || options . sourceRoot ) ) {
987
997
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
988
998
if ( options . mapRoot ) {
989
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_without_specifying_option_1 , "mapRoot" , "sourceMap" ) ) ;
999
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_without_specifying_option_1 , "mapRoot" , "sourceMap" ) ) ;
990
1000
}
991
1001
if ( options . sourceRoot ) {
992
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_without_specifying_option_1 , "sourceRoot" , "sourceMap" ) ) ;
1002
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_without_specifying_option_1 , "sourceRoot" , "sourceMap" ) ) ;
993
1003
}
994
1004
return ;
995
1005
}
@@ -1000,24 +1010,24 @@ namespace ts {
1000
1010
let firstExternalModuleSourceFile = forEach ( files , f => isExternalModule ( f ) ? f : undefined ) ;
1001
1011
if ( options . isolatedModules ) {
1002
1012
if ( ! options . module && languageVersion < ScriptTarget . ES6 ) {
1003
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher ) ) ;
1013
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher ) ) ;
1004
1014
}
1005
1015
1006
1016
let firstNonExternalModuleSourceFile = forEach ( files , f => ! isExternalModule ( f ) && ! isDeclarationFile ( f ) ? f : undefined ) ;
1007
1017
if ( firstNonExternalModuleSourceFile ) {
1008
1018
let span = getErrorSpanForNode ( firstNonExternalModuleSourceFile , firstNonExternalModuleSourceFile ) ;
1009
- diagnostics . add ( createFileDiagnostic ( firstNonExternalModuleSourceFile , span . start , span . length , Diagnostics . Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided ) ) ;
1019
+ programDiagnostics . add ( createFileDiagnostic ( firstNonExternalModuleSourceFile , span . start , span . length , Diagnostics . Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided ) ) ;
1010
1020
}
1011
1021
}
1012
1022
else if ( firstExternalModuleSourceFile && languageVersion < ScriptTarget . ES6 && ! options . module ) {
1013
1023
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
1014
1024
let span = getErrorSpanForNode ( firstExternalModuleSourceFile , firstExternalModuleSourceFile . externalModuleIndicator ) ;
1015
- diagnostics . add ( createFileDiagnostic ( firstExternalModuleSourceFile , span . start , span . length , Diagnostics . Cannot_compile_modules_unless_the_module_flag_is_provided ) ) ;
1025
+ programDiagnostics . add ( createFileDiagnostic ( firstExternalModuleSourceFile , span . start , span . length , Diagnostics . Cannot_compile_modules_unless_the_module_flag_is_provided ) ) ;
1016
1026
}
1017
1027
1018
1028
// Cannot specify module gen target when in es6 or above
1019
1029
if ( options . module && languageVersion >= ScriptTarget . ES6 ) {
1020
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher ) ) ;
1030
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher ) ) ;
1021
1031
}
1022
1032
1023
1033
// there has to be common source directory if user specified --outdir || --sourceRoot
@@ -1046,30 +1056,30 @@ namespace ts {
1046
1056
1047
1057
if ( options . noEmit ) {
1048
1058
if ( options . out ) {
1049
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmit" , "out" ) ) ;
1059
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmit" , "out" ) ) ;
1050
1060
}
1051
1061
1052
1062
if ( options . outFile ) {
1053
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmit" , "outFile" ) ) ;
1063
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmit" , "outFile" ) ) ;
1054
1064
}
1055
1065
1056
1066
if ( options . outDir ) {
1057
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmit" , "outDir" ) ) ;
1067
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmit" , "outDir" ) ) ;
1058
1068
}
1059
1069
1060
1070
if ( options . declaration ) {
1061
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmit" , "declaration" ) ) ;
1071
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "noEmit" , "declaration" ) ) ;
1062
1072
}
1063
1073
}
1064
1074
1065
1075
if ( options . emitDecoratorMetadata &&
1066
1076
! options . experimentalDecorators ) {
1067
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_without_specifying_option_1 , "emitDecoratorMetadata" , "experimentalDecorators" ) ) ;
1077
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_without_specifying_option_1 , "emitDecoratorMetadata" , "experimentalDecorators" ) ) ;
1068
1078
}
1069
1079
1070
1080
if ( options . experimentalAsyncFunctions &&
1071
1081
options . target !== ScriptTarget . ES6 ) {
1072
- diagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower ) ) ;
1082
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower ) ) ;
1073
1083
}
1074
1084
}
1075
1085
}
0 commit comments