@@ -502,41 +502,30 @@ namespace ts {
502
502
else {
503
503
const filesSeen : Map < boolean > = { } ;
504
504
const exclude = json [ "exclude" ] instanceof Array ? map ( < string [ ] > json [ "exclude" ] , normalizeSlashes ) : undefined ;
505
- const extensionsByPriority = getSupportedExtensions ( options ) ;
506
- for ( let extensionsIndex = 0 ; extensionsIndex < extensionsByPriority . length ; extensionsIndex ++ ) {
507
- const currentExtension = extensionsByPriority [ extensionsIndex ] ;
508
- const filesInDirWithExtension = host . readDirectory ( basePath , currentExtension , exclude ) ;
509
- // Get list of conflicting extensions, conflicting extension is
510
- // - extension that is lower priority than current extension and
511
- // - extension also is current extension (ends with "." + currentExtension)
512
- const conflictingExtensions : string [ ] = [ ] ;
513
- for ( let i = extensionsIndex + 1 ; i < extensionsByPriority . length ; i ++ ) {
514
- const extension = extensionsByPriority [ i ] ; // lower priority extension
515
- if ( fileExtensionIs ( extension , currentExtension ) ) { // also has current extension
516
- conflictingExtensions . push ( extension ) ;
517
- }
518
- }
505
+ const supportedExtensions = getSupportedExtensions ( options ) ;
506
+ Debug . assert ( indexOf ( supportedExtensions , ".ts" ) < indexOf ( supportedExtensions , ".d.ts" ) , "Changed priority of extensions to pick" ) ;
519
507
520
- // Add the files to fileNames list if the file is not any of conflicting extension
508
+ // Get files of supported extensions in their order of resolution
509
+ for ( const extension of supportedExtensions ) {
510
+ const filesInDirWithExtension = host . readDirectory ( basePath , extension , exclude ) ;
521
511
for ( const fileName of filesInDirWithExtension ) {
522
- let hasConflictingExtension = false ;
523
- for ( const conflictingExtension of conflictingExtensions ) {
524
- // eg. 'f.d.ts' will match '.ts' extension but really should be process later with '.d.ts' files
525
- if ( fileExtensionIs ( fileName , conflictingExtension ) ) {
526
- hasConflictingExtension = true ;
527
- break ;
528
- }
512
+ // .ts extension would read the .d.ts extension files too but since .d.ts is lower priority extension,
513
+ // lets pick them when its turn comes up
514
+ if ( extension === ".ts" && fileExtensionIs ( fileName , ".d.ts" ) ) {
515
+ continue ;
529
516
}
530
517
531
- if ( ! hasConflictingExtension ) {
532
- // Add the file only if there is no higher priority extension file already included
533
- // eg. when a.d.ts and a.js are present in the folder, include only a.d.ts not a.js
534
- const baseName = fileName . substr ( 0 , fileName . length - currentExtension . length ) ;
535
- if ( ! hasProperty ( filesSeen , baseName ) ) {
536
- filesSeen [ baseName ] = true ;
537
- fileNames . push ( fileName ) ;
518
+ // If this is one of the output extension (which would be .d.ts and .js if we are allowing compilation of js files)
519
+ // do not include this file if we included .ts or .tsx file with same base name as it could be output of the earlier compilation
520
+ if ( extension === ".d.ts" || ( options . allowJs && extension === ".js" ) ) {
521
+ const baseName = fileName . substr ( 0 , fileName . length - extension . length ) ;
522
+ if ( hasProperty ( filesSeen , baseName + ".ts" ) || hasProperty ( filesSeen , baseName + ".tsx" ) ) {
523
+ continue ;
538
524
}
539
525
}
526
+
527
+ filesSeen [ fileName ] = true ;
528
+ fileNames . push ( fileName ) ;
540
529
}
541
530
}
542
531
}
0 commit comments