diff --git a/compiler/packages/pastojs/src/pas2jsfilecache.pp b/compiler/packages/pastojs/src/pas2jsfilecache.pp index 88546e0..fe1992a 100644 --- a/compiler/packages/pastojs/src/pas2jsfilecache.pp +++ b/compiler/packages/pastojs/src/pas2jsfilecache.pp @@ -257,7 +257,7 @@ type function FindCustomJSFileName(const aFilename: string): String; override; function FindUnitJSFileName(const aUnitFilename: string): String; override; function FindUnitFileName(const aUnitname, InFilename, ModuleDir: string; out IsForeign: boolean): String; override; - function FindIncludeFileName(const aFilename: string): String; override; + function FindIncludeFileName(const aFilename, ModuleDir: string): String; override; function AddIncludePaths(const Paths: string; FromCmdLine: boolean; out ErrorMsg: string): boolean; function AddUnitPaths(const Paths: string; FromCmdLine: boolean; out ErrorMsg: string): boolean; function AddSrcUnitPaths(const Paths: string; FromCmdLine: boolean; out ErrorMsg: string): boolean; @@ -1812,7 +1812,8 @@ begin UsePointDirectory, true, RelPath); end; -function TPas2jsFilesCache.FindIncludeFileName(const aFilename: string): String; +function TPas2jsFilesCache.FindIncludeFileName(const aFilename, + ModuleDir: string): String; function SearchCasedInIncPath(const Filename: string): string; var @@ -1820,9 +1821,9 @@ function TPas2jsFilesCache.FindIncludeFileName(const aFilename: string): String; begin // file name is relative // first search in the same directory as the unit - if BaseDirectory<>'' then + if ModuleDir<>'' then begin - Result:=BaseDirectory+Filename; + Result:=IncludeTrailingPathDelimiter(ModuleDir)+Filename; if SearchLowUpCase(Result) then exit; end; // then search in include path diff --git a/compiler/packages/pastojs/src/pas2jsfs.pp b/compiler/packages/pastojs/src/pas2jsfs.pp index 090a046..357f3b7 100644 --- a/compiler/packages/pastojs/src/pas2jsfs.pp +++ b/compiler/packages/pastojs/src/pas2jsfs.pp @@ -96,7 +96,7 @@ Type function FindSourceFileName(const aFilename: string): String; virtual; abstract; Public // Public Abstract. Must be overridden - function FindIncludeFileName(const aFilename: string): String; virtual; abstract; + function FindIncludeFileName(const aFilename, ModuleDir: string): String; virtual; abstract; function LoadFile(Filename: string; Binary: boolean = false): TPas2jsFile; virtual; abstract; Function FileExists(Const aFileName: String): Boolean; virtual; abstract; function FindUnitJSFileName(const aUnitFilename: string): String; virtual; abstract; @@ -416,7 +416,7 @@ var Filename: String; begin Result:=nil; - Filename:=FS.FindIncludeFileName(aFilename); + Filename:=FS.FindIncludeFileName(aFilename,BaseDirectory); if Filename='' then exit; try Result:=FindSourceFile(Filename); @@ -433,7 +433,7 @@ end; function TPas2jsFSResolver.FindIncludeFileName(const aFilename: string): String; begin - Result:=FS.FindIncludeFileName(aFilename); + Result:=FS.FindIncludeFileName(aFilename,BaseDirectory); end; diff --git a/compiler/packages/pastojs/tests/tcmodules.pas b/compiler/packages/pastojs/tests/tcmodules.pas index 9b25b48..9f89e3e 100644 --- a/compiler/packages/pastojs/tests/tcmodules.pas +++ b/compiler/packages/pastojs/tests/tcmodules.pas @@ -3727,8 +3727,11 @@ begin ' s = ''end'';', ' s = "end";', ' return Result;', - '};' - ]), + '};', + 'this.Fly = function () {', + ' return;', + '};', + '']), LinesToStr([ '' ])); diff --git a/compiler/packages/pastojs/tests/tcunitsearch.pas b/compiler/packages/pastojs/tests/tcunitsearch.pas index 8d2c20d..2f40416 100644 --- a/compiler/packages/pastojs/tests/tcunitsearch.pas +++ b/compiler/packages/pastojs/tests/tcunitsearch.pas @@ -143,6 +143,7 @@ type procedure TestUS_Program_FU; procedure TestUS_Program_FU_o; procedure TestUS_Program_FE_o; + procedure TestUS_IncludeSameDir; procedure TestUS_UsesInFile; procedure TestUS_UsesInFile_Duplicate; @@ -695,6 +696,27 @@ begin AssertNotNull('foo.js not found',FindFile('foo.js')); end; +procedure TTestCLI_UnitSearch.TestUS_IncludeSameDir; +begin + AddUnit('system.pp',[''],['']); + AddFile('sub/defines.inc',[ + '{$Define foo}', + '']); + AddUnit('sub/unit1.pas', + ['{$I defines.inc}', + '{$ifdef foo}', + 'var a: longint;', + '{$endif}'], + ['']); + AddFile('test1.pas',[ + 'uses unit1;', + 'begin', + ' a:=3;', + 'end.']); + AddDir('lib'); + Compile(['test1.pas','-Fusub','-FElib','-ofoo.js']); +end; + procedure TTestCLI_UnitSearch.TestUS_UsesInFile; begin AddUnit('system.pp',[''],['']);