diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index 099807fa74..fec6dc8d04 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -13334,7 +13334,7 @@ begin {$IFDEF VerbosePas2JS} writeln('TPasToJSConverter.ConvertBuiltInConcatArray Count=',length(El.Params)); {$ENDIF} - Result:=ConvertExpression(Param0,AContext); + Result:=CreateArrayRef(El,ConvertExpression(Param0,AContext)); end else begin @@ -17619,6 +17619,8 @@ function TPasToJSConverter.CreateArrayRef(El: TPasElement; ArrayExpr: TJSElement var Call: TJSCallExpression; begin + if ArrayExpr is TJSArrayLiteral then + exit(ArrayExpr); Call:=CreateCallExpression(El); Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(pbifnArray_Reference)]); Call.AddArg(ArrayExpr); diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index 32879d616a..be5ec3d108 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -9878,16 +9878,16 @@ begin 'this.ArrJSValue = [];', '']), LinesToStr([ // $mod.$main - '$mod.ArrInt = $mod.ArrInt;', + '$mod.ArrInt = rtl.arrayRef($mod.ArrInt);', '$mod.ArrInt = rtl.arrayConcatN($mod.ArrInt, $mod.ArrInt);', '$mod.ArrInt = rtl.arrayConcatN($mod.ArrInt, $mod.ArrInt, $mod.ArrInt);', - '$mod.ArrRec = $mod.ArrRec;', + '$mod.ArrRec = rtl.arrayRef($mod.ArrRec);', '$mod.ArrRec = rtl.arrayConcat($mod.TRec, $mod.ArrRec, $mod.ArrRec);', '$mod.ArrRec = rtl.arrayConcat($mod.TRec, $mod.ArrRec, $mod.ArrRec, $mod.ArrRec);', - '$mod.ArrSet = $mod.ArrSet;', + '$mod.ArrSet = rtl.arrayRef($mod.ArrSet);', '$mod.ArrSet = rtl.arrayConcat("refSet", $mod.ArrSet, $mod.ArrSet);', '$mod.ArrSet = rtl.arrayConcat("refSet", $mod.ArrSet, $mod.ArrSet, $mod.ArrSet);', - '$mod.ArrJSValue = $mod.ArrJSValue;', + '$mod.ArrJSValue = rtl.arrayRef($mod.ArrJSValue);', '$mod.ArrJSValue = rtl.arrayConcatN($mod.ArrJSValue, $mod.ArrJSValue);', '$mod.ArrJSValue = rtl.arrayConcatN($mod.ArrJSValue, $mod.ArrJSValue, $mod.ArrJSValue);', '$mod.ArrInt = rtl.arrayConcatN([1], $mod.ArrInt);', diff --git a/utils/pas2js/dist/rtl.js b/utils/pas2js/dist/rtl.js index b119cacb85..8686207afc 100644 --- a/utils/pas2js/dist/rtl.js +++ b/utils/pas2js/dist/rtl.js @@ -1004,7 +1004,7 @@ var rtl = { var src = arguments[i]; if (src === null) continue; if (a===null){ - a=src; // Note: concat(a) does not clone + a=rtl.arrayRef(src); // Note: concat(a) does not clone } else { a=a.concat(src); }