@@ -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
}
@@ -1486,6 +1493,10 @@ namespace ts {
1486
1493
processReferencedFiles ( file , basePath ) ;
1487
1494
}
1488
1495
1496
+ const libraryRoot = computeCommonSourceDirectory ( files ) ;
1497
+
1498
+ processReferencedLibraries ( file , libraryRoot ) ;
1499
+
1489
1500
// always process imported modules to record module name resolutions
1490
1501
processImportedModules ( file , basePath ) ;
1491
1502
@@ -1507,6 +1518,25 @@ namespace ts {
1507
1518
} ) ;
1508
1519
}
1509
1520
1521
+ function processReferencedLibraries ( file : SourceFile , compilationRoot : string ) {
1522
+ const searchPaths = getEffectiveLibrarySearchPaths ( ) ;
1523
+ for ( const ref of file . referencedLibraries ) {
1524
+ for ( const path of searchPaths ) {
1525
+ const combinedPath = combinePaths ( path , ref . fileName ) ;
1526
+ if ( host . fileExists ( combinedPath ) ) {
1527
+ processSourceFile ( combinedPath , false , file , ref . pos , ref . end ) ;
1528
+ }
1529
+ }
1530
+ }
1531
+ }
1532
+
1533
+ function getEffectiveLibrarySearchPaths ( ) {
1534
+ return options . librarySearchPaths ||
1535
+ ( options . configFilePath ?
1536
+ [ options . configFilePath ] . concat ( defaultLibrarySearchPaths ) :
1537
+ defaultLibrarySearchPaths ) ;
1538
+ }
1539
+
1510
1540
function getCanonicalFileName ( fileName : string ) : string {
1511
1541
return host . getCanonicalFileName ( fileName ) ;
1512
1542
}
@@ -1742,7 +1772,7 @@ namespace ts {
1742
1772
1743
1773
// 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
1744
1774
if ( options . outDir && dir === "" && forEach ( files , file => getRootLength ( file . fileName ) > 1 ) ) {
1745
- programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_find_the_common_subdirectory_path_for_the_input_files ) ) ;
1775
+ programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_find_the_common_subdirectory_path_for_the_input_files ) ) ;
1746
1776
}
1747
1777
}
1748
1778
0 commit comments