@@ -584,7 +584,7 @@ namespace ts {
584
584
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles ( oldProgram , options ) ;
585
585
const structuralIsReused = tryReuseStructureFromOldProgram ( ) ;
586
586
if ( structuralIsReused !== StructureIsReused . Completely ) {
587
- forEach ( rootNames , name => processRootFile ( name , /*isDefaultLib*/ false ) ) ;
587
+ forEach ( rootNames , name => processRootFile ( name , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false ) ) ;
588
588
589
589
// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
590
590
const typeReferences : string [ ] = getAutomaticTypeDirectiveNames ( options , host ) ;
@@ -608,11 +608,11 @@ namespace ts {
608
608
// otherwise, using options specified in '--lib' instead of '--target' default library file
609
609
const defaultLibraryFileName = getDefaultLibraryFileName ( ) ;
610
610
if ( ! options . lib && defaultLibraryFileName ) {
611
- processRootFile ( defaultLibraryFileName , /*isDefaultLib*/ true ) ;
611
+ processRootFile ( defaultLibraryFileName , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ false ) ;
612
612
}
613
613
else {
614
614
forEach ( options . lib , libFileName => {
615
- processRootFile ( combinePaths ( defaultLibraryPath , libFileName ) , /*isDefaultLib*/ true ) ;
615
+ processRootFile ( combinePaths ( defaultLibraryPath , libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ false ) ;
616
616
} ) ;
617
617
}
618
618
}
@@ -964,6 +964,11 @@ namespace ts {
964
964
if ( fileChanged ) {
965
965
// The `newSourceFile` object was created for the new program.
966
966
967
+ if ( ! arrayIsEqualTo ( oldSourceFile . libReferenceDirectives , newSourceFile . libReferenceDirectives , fileReferenceIsEqualTo ) ) {
968
+ // 'lib' references has changed. Matches behavior in chagnesAffectModuleResolution
969
+ return oldProgram . structureIsReused = StructureIsReused . Not ;
970
+ }
971
+
967
972
if ( oldSourceFile . hasNoDefaultLib !== newSourceFile . hasNoDefaultLib ) {
968
973
// value of no-default-lib has changed
969
974
// this will affect if default library is injected into the list of files
@@ -1579,8 +1584,8 @@ namespace ts {
1579
1584
return configFileParsingDiagnostics || emptyArray ;
1580
1585
}
1581
1586
1582
- function processRootFile ( fileName : string , isDefaultLib : boolean ) {
1583
- processSourceFile ( normalizePath ( fileName ) , isDefaultLib , /*packageId*/ undefined ) ;
1587
+ function processRootFile ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean ) {
1588
+ processSourceFile ( normalizePath ( fileName ) , isDefaultLib , ignoreNoDefaultLib , /*packageId*/ undefined ) ;
1584
1589
}
1585
1590
1586
1591
function fileReferenceIsEqualTo ( a : FileReference , b : FileReference ) : boolean {
@@ -1747,9 +1752,9 @@ namespace ts {
1747
1752
}
1748
1753
1749
1754
/** This has side effects through `findSourceFile`. */
1750
- function processSourceFile ( fileName : string , isDefaultLib : boolean , packageId : PackageId | undefined , refFile ?: SourceFile , refPos ?: number , refEnd ?: number ) : void {
1755
+ function processSourceFile ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , packageId : PackageId | undefined , refFile ?: SourceFile , refPos ?: number , refEnd ?: number ) : void {
1751
1756
getSourceFileFromReferenceWorker ( fileName ,
1752
- fileName => findSourceFile ( fileName , toPath ( fileName ) , isDefaultLib , refFile , refPos , refEnd , packageId ) ,
1757
+ fileName => findSourceFile ( fileName , toPath ( fileName ) , isDefaultLib , ignoreNoDefaultLib , refFile , refPos , refEnd , packageId ) ,
1753
1758
( diagnostic , ...args ) => {
1754
1759
fileProcessingDiagnostics . add ( refFile !== undefined && refEnd !== undefined && refPos !== undefined
1755
1760
? createFileDiagnostic ( refFile , refPos , refEnd - refPos , diagnostic , ...args )
@@ -1787,7 +1792,7 @@ namespace ts {
1787
1792
}
1788
1793
1789
1794
// Get source file from normalized fileName
1790
- function findSourceFile ( fileName : string , path : Path , isDefaultLib : boolean , refFile : SourceFile , refPos : number , refEnd : number , packageId : PackageId | undefined ) : SourceFile | undefined {
1795
+ function findSourceFile ( fileName : string , path : Path , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , refFile : SourceFile , refPos : number , refEnd : number , packageId : PackageId | undefined ) : SourceFile | undefined {
1791
1796
if ( filesByName . has ( path ) ) {
1792
1797
const file = filesByName . get ( path ) ;
1793
1798
// try to check if we've already seen this file but with a different casing in path
@@ -1802,6 +1807,7 @@ namespace ts {
1802
1807
sourceFilesFoundSearchingNodeModules . set ( file . path , false ) ;
1803
1808
if ( ! options . noResolve ) {
1804
1809
processReferencedFiles ( file , isDefaultLib ) ;
1810
+ processLibReferenceDirectives ( file ) ;
1805
1811
processTypeReferenceDirectives ( file ) ;
1806
1812
}
1807
1813
@@ -1867,10 +1873,11 @@ namespace ts {
1867
1873
}
1868
1874
}
1869
1875
1870
- skipDefaultLib = skipDefaultLib || file . hasNoDefaultLib ;
1876
+ skipDefaultLib = skipDefaultLib || ( file . hasNoDefaultLib && ! ignoreNoDefaultLib ) ;
1871
1877
1872
1878
if ( ! options . noResolve ) {
1873
1879
processReferencedFiles ( file , isDefaultLib ) ;
1880
+ processLibReferenceDirectives ( file ) ;
1874
1881
processTypeReferenceDirectives ( file ) ;
1875
1882
}
1876
1883
@@ -1891,7 +1898,7 @@ namespace ts {
1891
1898
function processReferencedFiles ( file : SourceFile , isDefaultLib : boolean ) {
1892
1899
forEach ( file . referencedFiles , ref => {
1893
1900
const referencedFileName = resolveTripleslashReference ( ref . fileName , file . fileName ) ;
1894
- processSourceFile ( referencedFileName , isDefaultLib , /*packageId*/ undefined , file , ref . pos , ref . end ) ;
1901
+ processSourceFile ( referencedFileName , isDefaultLib , /*ignoreNoDefaultLib*/ false , /* packageId*/ undefined , file , ref . pos , ref . end ) ;
1895
1902
} ) ;
1896
1903
}
1897
1904
@@ -1922,7 +1929,7 @@ namespace ts {
1922
1929
if ( resolvedTypeReferenceDirective ) {
1923
1930
if ( resolvedTypeReferenceDirective . primary ) {
1924
1931
// resolved from the primary path
1925
- processSourceFile ( resolvedTypeReferenceDirective . resolvedFileName , /*isDefaultLib*/ false , resolvedTypeReferenceDirective . packageId , refFile , refPos , refEnd ) ;
1932
+ processSourceFile ( resolvedTypeReferenceDirective . resolvedFileName , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , resolvedTypeReferenceDirective . packageId , refFile , refPos , refEnd ) ;
1926
1933
}
1927
1934
else {
1928
1935
// If we already resolved to this file, it must have been a secondary reference. Check file contents
@@ -1945,7 +1952,7 @@ namespace ts {
1945
1952
}
1946
1953
else {
1947
1954
// First resolution of this library
1948
- processSourceFile ( resolvedTypeReferenceDirective . resolvedFileName , /*isDefaultLib*/ false , resolvedTypeReferenceDirective . packageId , refFile , refPos , refEnd ) ;
1955
+ processSourceFile ( resolvedTypeReferenceDirective . resolvedFileName , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , resolvedTypeReferenceDirective . packageId , refFile , refPos , refEnd ) ;
1949
1956
}
1950
1957
}
1951
1958
}
@@ -1958,6 +1965,23 @@ namespace ts {
1958
1965
}
1959
1966
}
1960
1967
1968
+ function processLibReferenceDirectives ( file : SourceFile ) {
1969
+ forEach ( file . libReferenceDirectives , libReference => {
1970
+ const libName = libReference . fileName . toLocaleLowerCase ( ) ;
1971
+ const libFileName = libMap . get ( libName ) ;
1972
+ if ( libFileName ) {
1973
+ // we ignore any 'no-default-lib' reference set on this file.
1974
+ processRootFile ( combinePaths ( defaultLibraryPath , libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ true ) ;
1975
+ }
1976
+ else {
1977
+ const unqualifiedLibName = removeSuffix ( removePrefix ( libName , "lib." ) , ".d.ts" ) ;
1978
+ const suggestion = getSpellingSuggestion ( unqualifiedLibName , libs , identity ) ;
1979
+ const message = suggestion ? Diagnostics . Cannot_find_lib_definition_for_0_Did_you_mean_1 : Diagnostics . Cannot_find_lib_definition_for_0 ;
1980
+ fileProcessingDiagnostics . add ( createDiagnostic ( file , libReference . pos , libReference . end , message , libName , suggestion ) ) ;
1981
+ }
1982
+ } ) ;
1983
+ }
1984
+
1961
1985
function createDiagnostic ( refFile : SourceFile , refPos : number , refEnd : number , message : DiagnosticMessage , ...args : any [ ] ) : Diagnostic {
1962
1986
if ( refFile === undefined || refPos === undefined || refEnd === undefined ) {
1963
1987
return createCompilerDiagnostic ( message , ...args ) ;
@@ -2018,7 +2042,7 @@ namespace ts {
2018
2042
else if ( shouldAddFile ) {
2019
2043
const path = toPath ( resolvedFileName ) ;
2020
2044
const pos = skipTrivia ( file . text , file . imports [ i ] . pos ) ;
2021
- findSourceFile ( resolvedFileName , path , /*isDefaultLib*/ false , file , pos , file . imports [ i ] . end , resolution . packageId ) ;
2045
+ findSourceFile ( resolvedFileName , path , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , file , pos , file . imports [ i ] . end , resolution . packageId ) ;
2022
2046
}
2023
2047
2024
2048
if ( isFromNodeModulesSearch ) {
0 commit comments