From 366ee5e8358fe47d89c47128413c1c62db7e2630 Mon Sep 17 00:00:00 2001 From: Mattias Gaertner Date: Mon, 30 Dec 2019 11:00:58 +0000 Subject: [PATCH] pastojs: added libpas2js hook SetPas2JSUnitAliasCallBack git-svn-id: trunk@43813 - --- packages/fcl-passrc/tests/tcresolver.pas | 31 +++++++++++++++++++++-- packages/pastojs/src/pas2jslibcompiler.pp | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/fcl-passrc/tests/tcresolver.pas b/packages/fcl-passrc/tests/tcresolver.pas index 6095266c4e..b0703c090b 100644 --- a/packages/fcl-passrc/tests/tcresolver.pas +++ b/packages/fcl-passrc/tests/tcresolver.pas @@ -379,6 +379,7 @@ type Procedure TestUnit_UnitNotFoundErrorPos; Procedure TestUnit_AccessIndirectUsedUnitFail; Procedure TestUnit_Intf1Impl2Intf1; + Procedure TestUnit_Intf1Impl2Intf1_Duplicate; // procs Procedure TestProcParam; @@ -2386,8 +2387,13 @@ function TCustomTestResolver.OnPasResolverFindUnit(SrcResolver: TPasResolver; {$ENDIF} CurEngine:=FindModuleWithFilename(aFilename); if CurEngine=nil then exit(false); - aModule:=InitUnit(CurEngine); - if aModule=nil then exit(false); + if CurEngine.Module=nil then + begin + aModule:=InitUnit(CurEngine); + if aModule=nil then exit(false); + end + else + aModule:=CurEngine.Module; OnPasResolverFindUnit:=aModule; Result:=true; end; @@ -6091,6 +6097,27 @@ begin ParseUnit; end; +procedure TTestResolver.TestUnit_Intf1Impl2Intf1_Duplicate; +begin + AddModuleWithIntfImplSrc('unit1.pp', + LinesToStr([ + 'type number = longint;']), + LinesToStr([ + 'uses afile;', + 'procedure DoIt;', + 'begin', + ' i:=3;', + 'end;'])); + + StartUnit(true); + Add([ + 'interface', + 'uses unit1, foo in ''unit1.pp'';', + 'var i: number;', + 'implementation']); + ParseUnit; +end; + procedure TTestResolver.TestProcParam; begin StartProgram(false); diff --git a/packages/pastojs/src/pas2jslibcompiler.pp b/packages/pastojs/src/pas2jslibcompiler.pp index 535cbfa452..bc4f15c294 100644 --- a/packages/pastojs/src/pas2jslibcompiler.pp +++ b/packages/pastojs/src/pas2jslibcompiler.pp @@ -212,7 +212,7 @@ begin UnitNameMaxLen:=Max(UnitNameLen,255); s:=UseUnitName; SetLength(s,UnitNameMaxLen); - if OnUnitAlias(OnUnitAliasData,Pointer(s),UnitNameLen,UnitNameMaxLen) then + if OnUnitAlias(OnUnitAliasData,Pointer(s),UnitNameMaxLen) then UseUnitName:=LeftStr(s,UnitNameLen); end; end;