File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -326,10 +326,11 @@ export class Project {
326
326
let searchFunction = fileNameOrSearchFunction as ( ( file : SourceFile ) => boolean ) ;
327
327
328
328
if ( typeof fileNameOrSearchFunction === "string" ) {
329
- if ( FileUtils . pathIsAbsolute ( fileNameOrSearchFunction ) )
330
- return this . global . compilerFactory . getSourceFileFromCacheFromFilePath ( fileNameOrSearchFunction ) ;
329
+ const fileNameOrPath = FileUtils . standardizeSlashes ( fileNameOrSearchFunction ) ;
330
+ if ( FileUtils . pathIsAbsolute ( fileNameOrPath ) || fileNameOrPath . indexOf ( "/" ) >= 0 )
331
+ return this . global . compilerFactory . getSourceFileFromCacheFromFilePath ( fileNameOrPath ) ;
331
332
else
332
- searchFunction = def => FileUtils . pathEndsWith ( def . getFilePath ( ) , fileNameOrSearchFunction ) ;
333
+ searchFunction = def => FileUtils . pathEndsWith ( def . getFilePath ( ) , fileNameOrPath ) ;
333
334
}
334
335
335
336
return ArrayUtils . find ( this . global . compilerFactory . getSourceFilesByDirectoryDepth ( ) , searchFunction ) ;
Original file line number Diff line number Diff line change @@ -511,6 +511,27 @@ describe(nameof(Project), () => {
511
511
expect ( project . getSourceFile ( "file.ts" ) ! . getFilePath ( ) ) . to . equal ( expectedFile . getFilePath ( ) ) ;
512
512
} ) ;
513
513
514
+ it ( "should get the first match based on the directory structure when specifying a dot slash" , ( ) => {
515
+ const project = new Project ( { useVirtualFileSystem : true } ) ;
516
+ project . createSourceFile ( "dir/file.ts" ) ;
517
+ const expectedFile = project . createSourceFile ( "file.ts" ) ;
518
+ expect ( project . getSourceFile ( "./file.ts" ) ! . getFilePath ( ) ) . to . equal ( expectedFile . getFilePath ( ) ) ;
519
+ } ) ;
520
+
521
+ it ( "should get the first match based on the directory structure when using ../" , ( ) => {
522
+ const project = new Project ( { useVirtualFileSystem : true } ) ;
523
+ const expectedFile = project . createSourceFile ( "dir/file.ts" ) ;
524
+ project . createSourceFile ( "file.ts" ) ;
525
+ expect ( project . getSourceFile ( "dir/../dir/file.ts" ) ! . getFilePath ( ) ) . to . equal ( expectedFile . getFilePath ( ) ) ;
526
+ } ) ;
527
+
528
+ it ( "should get the first match based on a file name" , ( ) => {
529
+ const project = new Project ( { useVirtualFileSystem : true } ) ;
530
+ project . createSourceFile ( "file.ts" ) ;
531
+ const expectedFile = project . createSourceFile ( "dir/file2.ts" ) ;
532
+ expect ( project . getSourceFile ( "file2.ts" ) ! . getFilePath ( ) ) . to . equal ( expectedFile . getFilePath ( ) ) ;
533
+ } ) ;
534
+
514
535
it ( "should get when specifying an absolute path" , ( ) => {
515
536
const project = new Project ( { useVirtualFileSystem : true } ) ;
516
537
project . createSourceFile ( "dir/file.ts" ) ;
You can’t perform that action at this time.
0 commit comments