From e89e010155466aafa1004ebe1c107a80b38e668e Mon Sep 17 00:00:00 2001 From: Mattias Gaertner Date: Thu, 25 Mar 2021 21:32:08 +0000 Subject: [PATCH] pastojs: filer: restore global shortref names git-svn-id: trunk@49053 - --- packages/pastojs/src/fppas2js.pp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index e48b8ecd4c..e70c07ff3d 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -7576,8 +7576,11 @@ var i: Integer; begin for i:=0 to length(PrecompiledVars)-1 do - if PrecompiledVars[i].Name=aName then - exit(PrecompiledVars[i]); + begin + Result:=PrecompiledVars[i]; + if Result.Name=aName then + exit; + end; if not WithParents then exit(nil); Result:=inherited FindPrecompiledVar(aName,WithParents); @@ -7589,8 +7592,11 @@ var i: Integer; begin for i:=0 to length(PrecompiledVars)-1 do - if PrecompiledVars[i].Element=El then - exit(PrecompiledVars[i]); + begin + Result:=PrecompiledVars[i]; + if Result.Element=El then + exit; + end; if not WithParents then exit(nil); Result:=inherited FindPrecompiledVar(El, WithParents); @@ -7623,6 +7629,7 @@ function TFunctionContext.AddLocalVar(aName: string; El: TPasElement; var l: Integer; Ident, V: TFCLocalIdentifier; + PV: TPas2JSStoredLocalVar; begin Ident:=FindLocalVar(aName,true); if Ident<>nil then @@ -7644,7 +7651,15 @@ begin raise EPas2JS.Create('[20200608131330] "'+aName+'" El='+GetObjPath(El)); end; end; + end + else if aKind=cvkGlobal then + begin + // check precompiled names + PV:=FindPrecompiledVar(El,true); + if PV<>nil then + aName:=PV.Name; end; + // add l:=length(LocalVars); SetLength(LocalVars,l+1); Result:=TFCLocalIdentifier.Create(aName,El,aKind); @@ -17016,6 +17031,7 @@ begin AddToSourceElements(ConstSrcElems,Lit); end; end; + if coShortRefGlobals in Options then CreateGlobalAlias_List(ImplJS.ShortRefs,AContext); // precompiled body