mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-06 10:37:49 +02:00
pastojs: fixed var a: somearray = nil
This commit is contained in:
parent
38894cfe96
commit
505a01b899
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user