@@ -12,6 +12,13 @@ namespace ts {
12
12
13
13
const emptyArray : any [ ] = [ ] ;
14
14
15
+ const defaultLibrarySearchPaths = [
16
+ './' ,
17
+ './typings/' ,
18
+ './node_modules/' ,
19
+ './node_modules/@types/' ,
20
+ ] ;
21
+
15
22
export const version = "1.9.0" ;
16
23
17
24
export function findConfigFile ( searchPath : string , fileExists : ( fileName : string ) => boolean ) : string {
@@ -371,7 +378,7 @@ namespace ts {
371
378
const traceEnabled = isTraceEnabled ( compilerOptions , host ) ;
372
379
373
380
const failedLookupLocations : string [ ] = [ ] ;
374
- const state = { compilerOptions, host, traceEnabled, skipTsx : false } ;
381
+ const state = { compilerOptions, host, traceEnabled, skipTsx : false } ;
375
382
let resolvedFileName = tryLoadModuleUsingOptionalResolutionSettings ( moduleName , containingDirectory , nodeLoadModuleByRelativeName ,
376
383
failedLookupLocations , supportedExtensions , state ) ;
377
384
@@ -407,7 +414,7 @@ namespace ts {
407
414
}
408
415
409
416
/* @internal */
410
- export function directoryProbablyExists ( directoryName : string , host : { directoryExists ?: ( directoryName : string ) => boolean } ) : boolean {
417
+ export function directoryProbablyExists ( directoryName : string , host : { directoryExists ?: ( directoryName : string ) => boolean } ) : boolean {
411
418
// if host does not support 'directoryExists' assume that directory will exist
412
419
return ! host . directoryExists || host . directoryExists ( directoryName ) ;
413
420
}
@@ -554,7 +561,7 @@ namespace ts {
554
561
555
562
556
563
return referencedSourceFile
557
- ? { resolvedModule : { resolvedFileName : referencedSourceFile } , failedLookupLocations }
564
+ ? { resolvedModule : { resolvedFileName : referencedSourceFile } , failedLookupLocations }
558
565
: { resolvedModule : undefined , failedLookupLocations } ;
559
566
}
560
567
@@ -649,9 +656,9 @@ namespace ts {
649
656
650
657
export function getPreEmitDiagnostics ( program : Program , sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : Diagnostic [ ] {
651
658
let diagnostics = program . getOptionsDiagnostics ( cancellationToken ) . concat (
652
- program . getSyntacticDiagnostics ( sourceFile , cancellationToken ) ,
653
- program . getGlobalDiagnostics ( cancellationToken ) ,
654
- program . getSemanticDiagnostics ( sourceFile , cancellationToken ) ) ;
659
+ program . getSyntacticDiagnostics ( sourceFile , cancellationToken ) ,
660
+ program . getGlobalDiagnostics ( cancellationToken ) ,
661
+ program . getSemanticDiagnostics ( sourceFile , cancellationToken ) ) ;
655
662
656
663
if ( program . getCompilerOptions ( ) . declaration ) {
657
664
diagnostics = diagnostics . concat ( program . getDeclarationDiagnostics ( sourceFile , cancellationToken ) ) ;
@@ -883,8 +890,8 @@ namespace ts {
883
890
const oldResolution = getResolvedModule ( oldSourceFile , moduleNames [ i ] ) ;
884
891
const resolutionChanged = oldResolution
885
892
? ! newResolution ||
886
- oldResolution . resolvedFileName !== newResolution . resolvedFileName ||
887
- ! ! oldResolution . isExternalLibraryImport !== ! ! newResolution . isExternalLibraryImport
893
+ oldResolution . resolvedFileName !== newResolution . resolvedFileName ||
894
+ ! ! oldResolution . isExternalLibraryImport !== ! ! newResolution . isExternalLibraryImport
888
895
: newResolution ;
889
896
890
897
if ( resolutionChanged ) {
@@ -1007,9 +1014,9 @@ namespace ts {
1007
1014
}
1008
1015
1009
1016
function getDiagnosticsHelper (
1010
- sourceFile : SourceFile ,
1011
- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => Diagnostic [ ] ,
1012
- cancellationToken : CancellationToken ) : Diagnostic [ ] {
1017
+ sourceFile : SourceFile ,
1018
+ getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => Diagnostic [ ] ,
1019
+ cancellationToken : CancellationToken ) : Diagnostic [ ] {
1013
1020
if ( sourceFile ) {
1014
1021
return getDiagnostics ( sourceFile , cancellationToken ) ;
1015
1022
}
@@ -1478,6 +1485,10 @@ namespace ts {
1478
1485
processReferencedFiles ( file , basePath ) ;
1479
1486
}
1480
1487
1488
+ const libraryRoot = computeCommonSourceDirectory ( files ) ;
1489
+
1490
+ processReferencedLibraries ( file , libraryRoot ) ;
1491
+
1481
1492
// always process imported modules to record module name resolutions
1482
1493
processImportedModules ( file , basePath ) ;
1483
1494
@@ -1499,6 +1510,25 @@ namespace ts {
1499
1510
} ) ;
1500
1511
}
1501
1512
1513
+ function processReferencedLibraries ( file : SourceFile , compilationRoot : string ) {
1514
+ const searchPaths = getEffectiveLibrarySearchPaths ( ) ;
1515
+ for ( const ref of file . referencedLibraries ) {
1516
+ for ( const path of searchPaths ) {
1517
+ const combinedPath = combinePaths ( path , ref . fileName ) ;
1518
+ if ( host . fileExists ( combinedPath ) ) {
1519
+ processSourceFile ( combinedPath , false , file , ref . pos , ref . end ) ;
1520
+ }
1521
+ }
1522
+ }
1523
+ }
1524
+
1525
+ function getEffectiveLibrarySearchPaths ( ) {
1526
+ return options . librarySearchPaths ||
1527
+ ( options . configFilePath ?
1528
+ [ options . configFilePath ] . concat ( defaultLibrarySearchPaths ) :
1529
+ defaultLibrarySearchPaths ) ;
1530
+ }
1531
+
1502
1532
function getCanonicalFileName ( fileName : string ) : string {
1503
1533
return host . getCanonicalFileName ( fileName ) ;
1504
1534
}
@@ -1734,7 +1764,7 @@ namespace ts {
1734
1764
1735
1765
// If we failed to find a good common directory, but outDir is specified and at least one of our files is on a windows drive/URL/other resource, add a failure
1736
1766
if ( options . outDir && dir === "" && forEach ( files , file => getRootLength ( file . fileName ) > 1 ) ) {
1737
- programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_find_the_common_subdirectory_path_for_the_input_files ) ) ;
1767
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_find_the_common_subdirectory_path_for_the_input_files ) ) ;
1738
1768
}
1739
1769
}
1740
1770
0 commit comments