From d8a2f7f7148486f86250a0773503381e6b54f343 Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 28 Feb 2024 11:51:20 +0100 Subject: [PATCH] pastojs: convert pascal ** to js ** --- packages/pastojs/src/fppas2js.pp | 9 ++------- packages/pastojs/tests/tcconverter.pas | 4 ++-- packages/pastojs/tests/tcmodules.pas | 4 +++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index 5e61448dea..89e9ec9200 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -9243,13 +9243,8 @@ begin C:=TJSBitwiseXOrExpression; // no logical xor in JS. bitwise works for boolean too end; eopPower: - begin - Call:=CreateCallExpression(El); - Call.Expr:=CreatePrimitiveDotExpr('Math.pow',El); - Call.AddArg(A); - Call.AddArg(B); - Result:=Call; - end; + // convert pascal ** to js ** + C:=TJSPowerExpression; else if C=nil then DoError(20161024191244,nBinaryOpcodeNotSupported,sBinaryOpcodeNotSupported,[OpcodeStrings[El.OpCode]],El); diff --git a/packages/pastojs/tests/tcconverter.pas b/packages/pastojs/tests/tcconverter.pas index 60be8155a9..83dba21932 100644 --- a/packages/pastojs/tests/tcconverter.pas +++ b/packages/pastojs/tests/tcconverter.pas @@ -1171,13 +1171,13 @@ end; procedure TTestExpressionConverter.TestBinaryPower; Var B : TBinaryExpr; - E : TJSRelationalExpressionInstanceOf; + E : TJSPowerExpression; begin B:=CreateBinary(eopPower); B.left:=CreateIdent('a'); B.Right:=CreateIdent('b'); - E:=TJSRelationalExpressionInstanceOf(TestBinaryExpression(B,TJSRelationalExpressionInstanceOf)); + E:=TJSPowerExpression(TestBinaryExpression(B,TJSPowerExpression)); AssertIdentifier('Correct left literal for power',E.A,'a'); AssertIdentifier('Correct right literal for power',E.B,'b'); end; diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index 69660a1e49..d701c5c1b8 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -7868,6 +7868,7 @@ begin ' d:=-004.00E-00;', ' d:=-005.00E-001;', ' d:=10**3;', + ' d:=100*9**0.5;', ' d:=10 mod 3;', ' d:=10 div 3;', ' d:=c;', @@ -7942,7 +7943,8 @@ begin '$mod.d = 3.000E0;', '$mod.d = -4.00E-0;', '$mod.d = -5.00E-1;', - '$mod.d = Math.pow(10, 3);', + '$mod.d = 10 ** 3;', + '$mod.d = 100 * (9 ** 0.5);', '$mod.d = 10 % 3;', '$mod.d = rtl.trunc(10 / 3);', '$mod.d = 1;',