فهرست منبع

fcl-js: fixed writing multi add

git-svn-id: trunk@49048 -
(cherry picked from commit 5eda61e136416fe812ad7f7597f14ec64ddac019)
Mattias Gaertner 4 سال پیش
والد
کامیت
cbee1110e4
2فایلهای تغییر یافته به همراه34 افزوده شده و 1 حذف شده
  1. 1 1
      packages/fcl-js/src/jswriter.pp
  2. 33 0
      packages/pastojs/tests/tcmodules.pas

+ 1 - 1
packages/fcl-js/src/jswriter.pp

@@ -1430,7 +1430,6 @@ begin
         or (ElC=TJSMultiplicativeExpressionMul)) then
     begin
     // handle left handed multi add without stack
-    FSkipRoundBrackets:=true;
     SetLength(Binaries{%H-},8);
     BinariesCnt:=0;
     while Left is TJSBinaryExpression do
@@ -1443,6 +1442,7 @@ begin
       inc(BinariesCnt);
       Left:=SubBin.A;
       end;
+
     WriteJS(Left);
     Writer.CurElement:=El;
 

+ 33 - 0
packages/pastojs/tests/tcmodules.pas

@@ -406,6 +406,7 @@ type
     Procedure TestLoHiDelphiMode;
     Procedure TestAssignments;
     Procedure TestArithmeticOperators1;
+    Procedure TestMultiAdd;
     Procedure TestLogicalOperators;
     Procedure TestBitwiseOperators;
     Procedure TestBitwiseOperatorsLongword;
@@ -3308,6 +3309,38 @@ begin
     ]));
 end;
 
+procedure TTestModule.TestMultiAdd;
+begin
+  StartProgram(false);
+  Add([
+  'function TryEncodeDate(Year, Month, Day: Word): Boolean;',
+  'var Date: double;',
+  'begin',
+  '  Result:=(Year>0) and (Year<10000) and',
+  '          (Month >= 1) and (Month<=12) and',
+  '          (Day>0) and (Day<=31);',
+  '  Date := (146097*Year) SHR 2 + (1461*Year) SHR 2 + (153*LongWord(Month)+2) DIV 5 + LongWord(Day);',
+  'end;',
+  'var s: string;',
+  'begin',
+  '  s:=''a''+''b''+''c''+''d'';']);
+  ConvertProgram;
+  CheckSource('TestMultiAdd',
+    LinesToStr([ // statements
+    'this.TryEncodeDate = function (Year, Month, Day) {',
+    '  var Result = false;',
+    '  var date = 0.0;',
+    '  Result = (Year > 0) && (Year < 10000) && (Month >= 1) && (Month <= 12) && (Day > 0) && (Day <= 31);',
+    '  date = ((146097 * Year) >>> 2) + ((1461 * Year) >>> 2) + rtl.trunc(((153 * Month) + 2) / 5) + Day;',
+    '  return Result;',
+    '};',
+    'this.s = "";',
+    '']),
+    LinesToStr([ // this.$main
+    '$mod.s = "a" + "b" + "c" + "d";',
+    '']));
+end;
+
 procedure TTestModule.TestLogicalOperators;
 begin
   StartProgram(false);