pastojs: fixed var a: somearray = nil

This commit is contained in:
mattias 2019-06-13 08:06:31 +00:00
parent 38894cfe96
commit 505a01b899
2 changed files with 36 additions and 1 deletions

View File

@ -15526,11 +15526,15 @@ begin
else if ExprResolved.BaseType in btAllStringAndChars then
begin
US:=StrToJSString(aResolver.ComputeConstString(Expr,false,true));
ArrLit:=TJSArrayLiteral(CreateElement(TJSArrayLiteral,El));
ArrLit:=TJSArrayLiteral(CreateElement(TJSArrayLiteral,Expr));
Result:=ArrLit;
for i:=1 to length(US) do
ArrLit.Elements.AddElement.Expr:=CreateLiteralJSString(Expr,US[i]);
end
else if ExprResolved.BaseType=btNil then
begin
Result:=TJSArrayLiteral(CreateElement(TJSArrayLiteral,Expr));
end
else
RaiseNotSupported(Expr,AContext,20170223133034);
end

View File

@ -335,6 +335,7 @@ type
Procedure TestProc_ConstOrder;
Procedure TestProc_DuplicateConst;
Procedure TestProc_LocalVarAbsolute;
Procedure TestProc_LocalVarInit;
Procedure TestProc_ReservedWords;
// anonymous functions
@ -4326,6 +4327,36 @@ begin
]));
end;
procedure TTestModule.TestProc_LocalVarInit;
begin
StartProgram(false);
Add([
'type TBytes = array of byte;',
'procedure DoIt;',
'const c = 4;',
'var',
' b: byte = 1;',
' w: word = 2+c;',
' p: pointer = nil;',
' Buffer: TBytes = nil;',
'begin',
'end;',
'begin']);
ConvertProgram;
CheckSource('TestProc_LocalVarInit',
LinesToStr([ // statements
'var c = 4;',
'this.DoIt = function () {',
' var b = 1;',
' var w = 2 + 4;',
' var p = null;',
' var Buffer = [];',
'};',
'']),
LinesToStr([
]));
end;
procedure TTestModule.TestProc_ReservedWords;
begin
StartProgram(false);