mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-06 02:27:48 +02:00
pas2js: fixed type helper nested procedure Self
This commit is contained in:
parent
31c1d6e401
commit
6f33a413a8
@ -14352,7 +14352,8 @@ begin
|
||||
or aResolver.HasAnonymousFunctions(ImplProc.Body.Body) then
|
||||
begin
|
||||
// has nested procs -> add "var self = this;"
|
||||
FuncContext.AddLocalVar(GetBIName(pbivnSelf),FuncContext.ThisPas);
|
||||
if ThisPas<>nil then
|
||||
FuncContext.AddLocalVar(GetBIName(pbivnSelf),ThisPas);
|
||||
SelfSt:=CreateVarStatement(GetBIName(pbivnSelf),
|
||||
CreatePrimitiveDotExpr('this',ImplProc),ImplProc);
|
||||
AddBodyStatement(SelfSt,PosEl);
|
||||
|
@ -696,6 +696,7 @@ type
|
||||
Procedure TestTypeHelper_Array;
|
||||
Procedure TestTypeHelper_EnumType;
|
||||
Procedure TestTypeHelper_SetType;
|
||||
Procedure TestTypeHelper_NestedSelf;
|
||||
|
||||
// proc types
|
||||
Procedure TestProcType;
|
||||
@ -23935,6 +23936,44 @@ begin
|
||||
'']));
|
||||
end;
|
||||
|
||||
procedure TTestModule.TestTypeHelper_NestedSelf;
|
||||
begin
|
||||
StartProgram(false);
|
||||
Add([
|
||||
'{$modeswitch typehelpers}',
|
||||
'type',
|
||||
' THelper = type helper for string',
|
||||
' procedure Run(Value: string);',
|
||||
' end;',
|
||||
'procedure THelper.Run(Value: string);',
|
||||
' function Sub(i: nativeint): boolean;',
|
||||
' begin',
|
||||
' Result:=Self[i+1]=Value[i];',
|
||||
' end;',
|
||||
'begin',
|
||||
' if Self[3]=Value[4] then ;',
|
||||
'end;',
|
||||
'begin',
|
||||
'']);
|
||||
ConvertProgram;
|
||||
CheckSource('TestTypeHelper_NestedSelf',
|
||||
LinesToStr([ // statements
|
||||
'rtl.createHelper($mod, "THelper", null, function () {',
|
||||
' this.Run = function (Value) {',
|
||||
' var $Self = this;',
|
||||
' function Sub(i) {',
|
||||
' var Result = false;',
|
||||
' Result = $Self.get().charAt((i + 1) - 1) === Value.charAt(i - 1);',
|
||||
' return Result;',
|
||||
' };',
|
||||
' if ($Self.get().charAt(2) === Value.charAt(3)) ;',
|
||||
' };',
|
||||
'});',
|
||||
'']),
|
||||
LinesToStr([ // $mod.$main
|
||||
'']));
|
||||
end;
|
||||
|
||||
procedure TTestModule.TestProcType;
|
||||
begin
|
||||
StartProgram(false);
|
||||
|
Loading…
Reference in New Issue
Block a user