@@ -1577,7 +1577,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
15771577 const host = createProgramOptionsHost || createCompilerHost ( options ) ;
15781578 const configParsingHost = parseConfigHostFromCompilerHostLike ( host ) ;
15791579
1580- let skipDefaultLib = options . noLib ;
15811580 const getDefaultLibraryFileName = memoize ( ( ) => host . getDefaultLibFileName ( options ) ) ;
15821581 const defaultLibraryPath = host . getDefaultLibLocation ? host . getDefaultLibLocation ( ) : getDirectoryPath ( getDefaultLibraryFileName ( ) ) ;
15831582
@@ -1708,6 +1707,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
17081707 * - undefined otherwise
17091708 */
17101709 const filesByName = new Map < Path , SourceFile | false | undefined > ( ) ;
1710+ const libFiles = new Set < Path > ( ) ;
17111711 let missingFileNames = new Map < Path , string > ( ) ;
17121712 // stores 'filename -> file association' ignoring case
17131713 // used to track cases when two file names differ only in casing
@@ -1779,7 +1779,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
17791779 }
17801780
17811781 tracing ?. push ( tracing . Phase . Program , "processRootFiles" , { count : rootNames . length } ) ;
1782- forEach ( rootNames , ( name , index ) => processRootFile ( name , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , { kind : FileIncludeKind . RootFile , index } ) ) ;
1782+ forEach ( rootNames , ( name , index ) => processRootFile ( name , /*isDefaultLib*/ false , { kind : FileIncludeKind . RootFile , index } ) ) ;
17831783 tracing ?. pop ( ) ;
17841784
17851785 // load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
@@ -1808,20 +1808,16 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
18081808 tracing ?. pop ( ) ;
18091809 }
18101810
1811- // Do not process the default library if:
1812- // - The '--noLib' flag is used.
1813- // - A 'no-default-lib' reference comment is encountered in
1814- // processing the root files.
1815- if ( rootNames . length && ! skipDefaultLib ) {
1811+ if ( rootNames . length && ! options . noLib ) {
18161812 // If '--lib' is not specified, include default library file according to '--target'
18171813 // otherwise, using options specified in '--lib' instead of '--target' default library file
18181814 const defaultLibraryFileName = getDefaultLibraryFileName ( ) ;
18191815 if ( ! options . lib && defaultLibraryFileName ) {
1820- processRootFile ( defaultLibraryFileName , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ false , { kind : FileIncludeKind . LibFile } ) ;
1816+ processRootFile ( defaultLibraryFileName , /*isDefaultLib*/ true , { kind : FileIncludeKind . LibFile } ) ;
18211817 }
18221818 else {
18231819 forEach ( options . lib , ( libFileName , index ) => {
1824- processRootFile ( pathForLibFile ( libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ false , { kind : FileIncludeKind . LibFile , index } ) ;
1820+ processRootFile ( pathForLibFile ( libFileName ) , /*isDefaultLib*/ true , { kind : FileIncludeKind . LibFile , index } ) ;
18251821 } ) ;
18261822 }
18271823 }
@@ -2453,11 +2449,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
24532449 // 'lib' references has changed. Matches behavior in changesAffectModuleResolution
24542450 structureIsReused = StructureIsReused . SafeModules ;
24552451 }
2456- else if ( oldSourceFile . hasNoDefaultLib !== newSourceFile . hasNoDefaultLib ) {
2457- // value of no-default-lib has changed
2458- // this will affect if default library is injected into the list of files
2459- structureIsReused = StructureIsReused . SafeModules ;
2460- }
24612452 // check tripleslash references
24622453 else if ( ! arrayIsEqualTo ( oldSourceFile . referencedFiles , newSourceFile . referencedFiles , fileReferenceIsEqualTo ) ) {
24632454 // tripleslash references has changed
@@ -2687,7 +2678,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
26872678 return false ;
26882679 }
26892680
2690- if ( file . hasNoDefaultLib ) {
2681+ if ( libFiles . has ( file . path ) ) {
26912682 return true ;
26922683 }
26932684
@@ -2703,7 +2694,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
27032694 }
27042695 else {
27052696 return some ( options . lib , libFileName => {
2706- // We might not have resolved lib if one of the root file included contained no-default-lib = true
27072697 const resolvedLib = resolvedLibReferences ! . get ( libFileName ) ;
27082698 return ! ! resolvedLib && equalityComparer ( file . fileName , resolvedLib . actual ) ;
27092699 } ) ;
@@ -3317,8 +3307,8 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
33173307 return configFileParsingDiagnostics || emptyArray ;
33183308 }
33193309
3320- function processRootFile ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , reason : FileIncludeReason ) {
3321- processSourceFile ( normalizePath ( fileName ) , isDefaultLib , ignoreNoDefaultLib , /*packageId*/ undefined , reason ) ;
3310+ function processRootFile ( fileName : string , isDefaultLib : boolean , reason : FileIncludeReason ) {
3311+ processSourceFile ( normalizePath ( fileName ) , isDefaultLib , /*packageId*/ undefined , reason ) ;
33223312 }
33233313
33243314 function fileReferenceIsEqualTo ( a : FileReference , b : FileReference ) : boolean {
@@ -3512,17 +3502,17 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
35123502 }
35133503
35143504 /** This has side effects through `findSourceFile`. */
3515- function processSourceFile ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , packageId : PackageId | undefined , reason : FileIncludeReason ) : void {
3505+ function processSourceFile ( fileName : string , isDefaultLib : boolean , packageId : PackageId | undefined , reason : FileIncludeReason ) : void {
35163506 getSourceFileFromReferenceWorker (
35173507 fileName ,
3518- fileName => findSourceFile ( fileName , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) , // TODO: GH#18217
3508+ fileName => findSourceFile ( fileName , isDefaultLib , reason , packageId ) , // TODO: GH#18217
35193509 ( diagnostic , ...args ) => addFilePreprocessingFileExplainingDiagnostic ( /*file*/ undefined , reason , diagnostic , args ) ,
35203510 reason ,
35213511 ) ;
35223512 }
35233513
35243514 function processProjectReferenceFile ( fileName : string , reason : ProjectReferenceFile ) {
3525- return processSourceFile ( fileName , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , /* packageId*/ undefined , reason ) ;
3515+ return processSourceFile ( fileName , /*isDefaultLib*/ false , /*packageId*/ undefined , reason ) ;
35263516 }
35273517
35283518 function reportFileNamesDifferOnlyInCasingError ( fileName : string , existingFile : SourceFile , reason : FileIncludeReason ) : void {
@@ -3548,13 +3538,13 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
35483538 }
35493539
35503540 // Get source file from normalized fileName
3551- function findSourceFile ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , reason : FileIncludeReason , packageId : PackageId | undefined ) : SourceFile | undefined {
3541+ function findSourceFile ( fileName : string , isDefaultLib : boolean , reason : FileIncludeReason , packageId : PackageId | undefined ) : SourceFile | undefined {
35523542 tracing ?. push ( tracing . Phase . Program , "findSourceFile" , {
35533543 fileName,
35543544 isDefaultLib : isDefaultLib || undefined ,
35553545 fileIncludeKind : ( FileIncludeKind as any ) [ reason . kind ] ,
35563546 } ) ;
3557- const result = findSourceFileWorker ( fileName , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) ;
3547+ const result = findSourceFileWorker ( fileName , isDefaultLib , reason , packageId ) ;
35583548 tracing ?. pop ( ) ;
35593549 return result ;
35603550 }
@@ -3571,7 +3561,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
35713561 { languageVersion, impliedNodeFormat : result , setExternalModuleIndicator, jsDocParsingMode : host . jsDocParsingMode } ;
35723562 }
35733563
3574- function findSourceFileWorker ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , reason : FileIncludeReason , packageId : PackageId | undefined ) : SourceFile | undefined {
3564+ function findSourceFileWorker ( fileName : string , isDefaultLib : boolean , reason : FileIncludeReason , packageId : PackageId | undefined ) : SourceFile | undefined {
35753565 const path = toPath ( fileName ) ;
35763566 if ( useSourceOfProjectReferenceRedirect ) {
35773567 let source = getRedirectFromOutput ( path ) ;
@@ -3590,7 +3580,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
35903580 if ( realPath !== path ) source = getRedirectFromOutput ( realPath ) ;
35913581 }
35923582 if ( source ?. source ) {
3593- const file = findSourceFile ( source . source , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) ;
3583+ const file = findSourceFile ( source . source , isDefaultLib , reason , packageId ) ;
35943584 if ( file ) addFileToFilesByName ( file , path , fileName , /*redirectedPath*/ undefined ) ;
35953585 return file ;
35963586 }
@@ -3712,8 +3702,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
37123702 }
37133703 }
37143704
3715- skipDefaultLib = skipDefaultLib || ( file . hasNoDefaultLib && ! ignoreNoDefaultLib ) ;
3716-
37173705 if ( ! options . noResolve ) {
37183706 processReferencedFiles ( file , isDefaultLib ) ;
37193707 processTypeReferenceDirectives ( file ) ;
@@ -3727,6 +3715,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
37273715
37283716 if ( isDefaultLib ) {
37293717 processingDefaultLibFiles ! . push ( file ) ;
3718+ libFiles . add ( file . path ) ;
37303719 }
37313720 else {
37323721 processingOtherFiles ! . push ( file ) ;
@@ -3793,7 +3782,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
37933782 processSourceFile (
37943783 resolveTripleslashReference ( ref . fileName , file . fileName ) ,
37953784 isDefaultLib ,
3796- /*ignoreNoDefaultLib*/ false ,
37973785 /*packageId*/ undefined ,
37983786 { kind : FileIncludeKind . ReferenceFile , file : file . path , index } ,
37993787 ) ;
@@ -3846,7 +3834,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
38463834 if ( resolvedTypeReferenceDirective . isExternalLibraryImport ) currentNodeModulesDepth ++ ;
38473835
38483836 // resolved from the primary path
3849- processSourceFile ( resolvedTypeReferenceDirective . resolvedFileName ! , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , resolvedTypeReferenceDirective . packageId , reason ) ; // TODO: GH#18217
3837+ processSourceFile ( resolvedTypeReferenceDirective . resolvedFileName ! , /*isDefaultLib*/ false , resolvedTypeReferenceDirective . packageId , reason ) ; // TODO: GH#18217
38503838
38513839 if ( resolvedTypeReferenceDirective . isExternalLibraryImport ) currentNodeModulesDepth -- ;
38523840 }
@@ -3924,8 +3912,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
39243912 forEach ( file . libReferenceDirectives , ( libReference , index ) => {
39253913 const libFileName = getLibFileNameFromLibReference ( libReference ) ;
39263914 if ( libFileName ) {
3927- // we ignore any 'no-default-lib' reference set on this file.
3928- processRootFile ( pathForLibFile ( libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ true , { kind : FileIncludeKind . LibReferenceDirective , file : file . path , index } ) ;
3915+ processRootFile ( pathForLibFile ( libFileName ) , /*isDefaultLib*/ true , { kind : FileIncludeKind . LibReferenceDirective , file : file . path , index } ) ;
39293916 }
39303917 else {
39313918 programDiagnostics . addFileProcessingDiagnostic ( {
@@ -3995,7 +3982,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
39953982 findSourceFile (
39963983 resolvedFileName ,
39973984 /*isDefaultLib*/ false ,
3998- /*ignoreNoDefaultLib*/ false ,
39993985 { kind : FileIncludeKind . Import , file : file . path , index } ,
40003986 resolution . packageId ,
40013987 ) ;
0 commit comments