@@ -1577,7 +1577,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
1577
1577
const host = createProgramOptionsHost || createCompilerHost ( options ) ;
1578
1578
const configParsingHost = parseConfigHostFromCompilerHostLike ( host ) ;
1579
1579
1580
- let skipDefaultLib = options . noLib ;
1581
1580
const getDefaultLibraryFileName = memoize ( ( ) => host . getDefaultLibFileName ( options ) ) ;
1582
1581
const defaultLibraryPath = host . getDefaultLibLocation ? host . getDefaultLibLocation ( ) : getDirectoryPath ( getDefaultLibraryFileName ( ) ) ;
1583
1582
@@ -1708,6 +1707,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
1708
1707
* - undefined otherwise
1709
1708
*/
1710
1709
const filesByName = new Map < Path , SourceFile | false | undefined > ( ) ;
1710
+ const libFiles = new Set < Path > ( ) ;
1711
1711
let missingFileNames = new Map < Path , string > ( ) ;
1712
1712
// stores 'filename -> file association' ignoring case
1713
1713
// used to track cases when two file names differ only in casing
@@ -1779,7 +1779,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
1779
1779
}
1780
1780
1781
1781
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 } ) ) ;
1783
1783
tracing ?. pop ( ) ;
1784
1784
1785
1785
// 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
1808
1808
tracing ?. pop ( ) ;
1809
1809
}
1810
1810
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 ) {
1816
1812
// If '--lib' is not specified, include default library file according to '--target'
1817
1813
// otherwise, using options specified in '--lib' instead of '--target' default library file
1818
1814
const defaultLibraryFileName = getDefaultLibraryFileName ( ) ;
1819
1815
if ( ! options . lib && defaultLibraryFileName ) {
1820
- processRootFile ( defaultLibraryFileName , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ false , { kind : FileIncludeKind . LibFile } ) ;
1816
+ processRootFile ( defaultLibraryFileName , /*isDefaultLib*/ true , { kind : FileIncludeKind . LibFile } ) ;
1821
1817
}
1822
1818
else {
1823
1819
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 } ) ;
1825
1821
} ) ;
1826
1822
}
1827
1823
}
@@ -2453,11 +2449,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
2453
2449
// 'lib' references has changed. Matches behavior in changesAffectModuleResolution
2454
2450
structureIsReused = StructureIsReused . SafeModules ;
2455
2451
}
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
- }
2461
2452
// check tripleslash references
2462
2453
else if ( ! arrayIsEqualTo ( oldSourceFile . referencedFiles , newSourceFile . referencedFiles , fileReferenceIsEqualTo ) ) {
2463
2454
// tripleslash references has changed
@@ -2687,7 +2678,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
2687
2678
return false ;
2688
2679
}
2689
2680
2690
- if ( file . hasNoDefaultLib ) {
2681
+ if ( libFiles . has ( file . path ) ) {
2691
2682
return true ;
2692
2683
}
2693
2684
@@ -2703,7 +2694,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
2703
2694
}
2704
2695
else {
2705
2696
return some ( options . lib , libFileName => {
2706
- // We might not have resolved lib if one of the root file included contained no-default-lib = true
2707
2697
const resolvedLib = resolvedLibReferences ! . get ( libFileName ) ;
2708
2698
return ! ! resolvedLib && equalityComparer ( file . fileName , resolvedLib . actual ) ;
2709
2699
} ) ;
@@ -3317,8 +3307,8 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3317
3307
return configFileParsingDiagnostics || emptyArray ;
3318
3308
}
3319
3309
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 ) ;
3322
3312
}
3323
3313
3324
3314
function fileReferenceIsEqualTo ( a : FileReference , b : FileReference ) : boolean {
@@ -3512,17 +3502,17 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3512
3502
}
3513
3503
3514
3504
/** 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 {
3516
3506
getSourceFileFromReferenceWorker (
3517
3507
fileName ,
3518
- fileName => findSourceFile ( fileName , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) , // TODO: GH#18217
3508
+ fileName => findSourceFile ( fileName , isDefaultLib , reason , packageId ) , // TODO: GH#18217
3519
3509
( diagnostic , ...args ) => addFilePreprocessingFileExplainingDiagnostic ( /*file*/ undefined , reason , diagnostic , args ) ,
3520
3510
reason ,
3521
3511
) ;
3522
3512
}
3523
3513
3524
3514
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 ) ;
3526
3516
}
3527
3517
3528
3518
function reportFileNamesDifferOnlyInCasingError ( fileName : string , existingFile : SourceFile , reason : FileIncludeReason ) : void {
@@ -3548,13 +3538,13 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3548
3538
}
3549
3539
3550
3540
// 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 {
3552
3542
tracing ?. push ( tracing . Phase . Program , "findSourceFile" , {
3553
3543
fileName,
3554
3544
isDefaultLib : isDefaultLib || undefined ,
3555
3545
fileIncludeKind : ( FileIncludeKind as any ) [ reason . kind ] ,
3556
3546
} ) ;
3557
- const result = findSourceFileWorker ( fileName , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) ;
3547
+ const result = findSourceFileWorker ( fileName , isDefaultLib , reason , packageId ) ;
3558
3548
tracing ?. pop ( ) ;
3559
3549
return result ;
3560
3550
}
@@ -3571,7 +3561,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3571
3561
{ languageVersion, impliedNodeFormat : result , setExternalModuleIndicator, jsDocParsingMode : host . jsDocParsingMode } ;
3572
3562
}
3573
3563
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 {
3575
3565
const path = toPath ( fileName ) ;
3576
3566
if ( useSourceOfProjectReferenceRedirect ) {
3577
3567
let source = getRedirectFromOutput ( path ) ;
@@ -3590,7 +3580,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3590
3580
if ( realPath !== path ) source = getRedirectFromOutput ( realPath ) ;
3591
3581
}
3592
3582
if ( source ?. source ) {
3593
- const file = findSourceFile ( source . source , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) ;
3583
+ const file = findSourceFile ( source . source , isDefaultLib , reason , packageId ) ;
3594
3584
if ( file ) addFileToFilesByName ( file , path , fileName , /*redirectedPath*/ undefined ) ;
3595
3585
return file ;
3596
3586
}
@@ -3712,8 +3702,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3712
3702
}
3713
3703
}
3714
3704
3715
- skipDefaultLib = skipDefaultLib || ( file . hasNoDefaultLib && ! ignoreNoDefaultLib ) ;
3716
-
3717
3705
if ( ! options . noResolve ) {
3718
3706
processReferencedFiles ( file , isDefaultLib ) ;
3719
3707
processTypeReferenceDirectives ( file ) ;
@@ -3727,6 +3715,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3727
3715
3728
3716
if ( isDefaultLib ) {
3729
3717
processingDefaultLibFiles ! . push ( file ) ;
3718
+ libFiles . add ( file . path ) ;
3730
3719
}
3731
3720
else {
3732
3721
processingOtherFiles ! . push ( file ) ;
@@ -3793,7 +3782,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3793
3782
processSourceFile (
3794
3783
resolveTripleslashReference ( ref . fileName , file . fileName ) ,
3795
3784
isDefaultLib ,
3796
- /*ignoreNoDefaultLib*/ false ,
3797
3785
/*packageId*/ undefined ,
3798
3786
{ kind : FileIncludeKind . ReferenceFile , file : file . path , index } ,
3799
3787
) ;
@@ -3846,7 +3834,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3846
3834
if ( resolvedTypeReferenceDirective . isExternalLibraryImport ) currentNodeModulesDepth ++ ;
3847
3835
3848
3836
// 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
3850
3838
3851
3839
if ( resolvedTypeReferenceDirective . isExternalLibraryImport ) currentNodeModulesDepth -- ;
3852
3840
}
@@ -3924,8 +3912,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3924
3912
forEach ( file . libReferenceDirectives , ( libReference , index ) => {
3925
3913
const libFileName = getLibFileNameFromLibReference ( libReference ) ;
3926
3914
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 } ) ;
3929
3916
}
3930
3917
else {
3931
3918
programDiagnostics . addFileProcessingDiagnostic ( {
@@ -3995,7 +3982,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
3995
3982
findSourceFile (
3996
3983
resolvedFileName ,
3997
3984
/*isDefaultLib*/ false ,
3998
- /*ignoreNoDefaultLib*/ false ,
3999
3985
{ kind : FileIncludeKind . Import , file : file . path , index } ,
4000
3986
resolution . packageId ,
4001
3987
) ;
0 commit comments