@@ -438,6 +438,8 @@ namespace ts {
438
438
host = host || createCompilerHost ( options ) ;
439
439
440
440
let skipDefaultLib = options . noLib ;
441
+ const getDefaultLibraryFileName = memoize ( ( ) => host . getDefaultLibFileName ( options ) ) ;
442
+ const defaultLibraryPath = host . getDefaultLibLocation ? host . getDefaultLibLocation ( ) : getDirectoryPath ( getDefaultLibraryFileName ( ) ) ;
441
443
const programDiagnostics = createDiagnosticCollection ( ) ;
442
444
const currentDirectory = host . getCurrentDirectory ( ) ;
443
445
const supportedExtensions = getSupportedExtensions ( options ) ;
@@ -513,12 +515,11 @@ namespace ts {
513
515
// If '--lib' is not specified, include default library file according to '--target'
514
516
// otherwise, using options specified in '--lib' instead of '--target' default library file
515
517
if ( ! options . lib ) {
516
- processRootFile ( host . getDefaultLibFileName ( options ) , /*isDefaultLib*/ true ) ;
518
+ processRootFile ( getDefaultLibraryFileName ( ) , /*isDefaultLib*/ true ) ;
517
519
}
518
520
else {
519
- const libDirectory = host . getDefaultLibLocation ? host . getDefaultLibLocation ( ) : getDirectoryPath ( host . getDefaultLibFileName ( options ) ) ;
520
521
forEach ( options . lib , libFileName => {
521
- processRootFile ( combinePaths ( libDirectory , libFileName ) , /*isDefaultLib*/ true ) ;
522
+ processRootFile ( combinePaths ( defaultLibraryPath , libFileName ) , /*isDefaultLib*/ true ) ;
522
523
} ) ;
523
524
}
524
525
}
@@ -557,6 +558,7 @@ namespace ts {
557
558
getFileProcessingDiagnostics : ( ) => fileProcessingDiagnostics ,
558
559
getResolvedTypeReferenceDirectives : ( ) => resolvedTypeReferenceDirectives ,
559
560
isSourceFileFromExternalLibrary,
561
+ isSourceFileDefaultLibrary,
560
562
dropDiagnosticsProducingTypeChecker,
561
563
getSourceFileFromReference,
562
564
sourceFileToPackageName,
@@ -977,6 +979,18 @@ namespace ts {
977
979
return sourceFilesFoundSearchingNodeModules . get ( file . path ) ;
978
980
}
979
981
982
+ function isSourceFileDefaultLibrary ( file : SourceFile ) : boolean {
983
+ if ( file . hasNoDefaultLib ) {
984
+ return true ;
985
+ }
986
+
987
+ if ( defaultLibraryPath && defaultLibraryPath . length !== 0 ) {
988
+ return containsPath ( defaultLibraryPath , file . path , currentDirectory , /*ignoreCase*/ ! host . useCaseSensitiveFileNames ( ) ) ;
989
+ }
990
+
991
+ return compareStrings ( file . fileName , getDefaultLibraryFileName ( ) , /*ignoreCase*/ ! host . useCaseSensitiveFileNames ( ) ) === Comparison . EqualTo ;
992
+ }
993
+
980
994
function getDiagnosticsProducingTypeChecker ( ) {
981
995
return diagnosticsProducingTypeChecker || ( diagnosticsProducingTypeChecker = createTypeChecker ( program , /*produceDiagnostics:*/ true ) ) ;
982
996
}
@@ -1208,7 +1222,7 @@ namespace ts {
1208
1222
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . _0_can_only_be_used_in_a_ts_file , "?" ) ) ;
1209
1223
return ;
1210
1224
}
1211
- // falls through
1225
+ // falls through
1212
1226
case SyntaxKind . MethodDeclaration :
1213
1227
case SyntaxKind . MethodSignature :
1214
1228
case SyntaxKind . Constructor :
@@ -1290,7 +1304,7 @@ namespace ts {
1290
1304
diagnostics . push ( createDiagnosticForNodeArray ( nodes , Diagnostics . type_parameter_declarations_can_only_be_used_in_a_ts_file ) ) ;
1291
1305
return ;
1292
1306
}
1293
- // falls through
1307
+ // falls through
1294
1308
case SyntaxKind . VariableStatement :
1295
1309
// Check modifiers
1296
1310
if ( nodes === ( < ClassDeclaration | FunctionLikeDeclaration | VariableStatement > parent ) . modifiers ) {
@@ -1338,8 +1352,8 @@ namespace ts {
1338
1352
if ( isConstValid ) {
1339
1353
continue ;
1340
1354
}
1341
- // to report error,
1342
- // falls through
1355
+ // to report error,
1356
+ // falls through
1343
1357
case SyntaxKind . PublicKeyword :
1344
1358
case SyntaxKind . PrivateKeyword :
1345
1359
case SyntaxKind . ProtectedKeyword :
@@ -1553,10 +1567,10 @@ namespace ts {
1553
1567
}
1554
1568
1555
1569
function getSourceFileFromReferenceWorker (
1556
- fileName : string ,
1557
- getSourceFile : ( fileName : string ) => SourceFile | undefined ,
1558
- fail ?: ( diagnostic : DiagnosticMessage , ...argument : string [ ] ) => void ,
1559
- refFile ?: SourceFile ) : SourceFile | undefined {
1570
+ fileName : string ,
1571
+ getSourceFile : ( fileName : string ) => SourceFile | undefined ,
1572
+ fail ?: ( diagnostic : DiagnosticMessage , ...argument : string [ ] ) => void ,
1573
+ refFile ?: SourceFile ) : SourceFile | undefined {
1560
1574
1561
1575
if ( hasExtension ( fileName ) ) {
1562
1576
if ( ! options . allowNonTsExtensions && ! forEach ( supportedExtensions , extension => fileExtensionIs ( host . getCanonicalFileName ( fileName ) , extension ) ) ) {
0 commit comments