|
@@ -6277,19 +6277,35 @@ function TPasToJSConverter.ConvertPrimitiveExpression(El: TPrimitiveExpr;
|
|
|
|
|
|
function DeleteLeadingZeroes(const s: string): string;
|
|
function DeleteLeadingZeroes(const s: string): string;
|
|
// Note: 01 is in JS octal, and in strict mode forbidden
|
|
// Note: 01 is in JS octal, and in strict mode forbidden
|
|
|
|
+ // $00ff00 -> $ff00
|
|
|
|
+ // 00E001 -> 0E1
|
|
|
|
+ // 0.001 -> 0.001
|
|
|
|
+ // 0.00E1 -> 0.00E1
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
begin
|
|
begin
|
|
Result:=s;
|
|
Result:=s;
|
|
i:=1;
|
|
i:=1;
|
|
- while i<length(Result) do
|
|
|
|
- begin
|
|
|
|
- if (Result[i]='0') and (Result[i+1] in ['0'..'9'])
|
|
|
|
- and ((i=1) or not (Result[i-1] in ['.','0'..'9'])) then
|
|
|
|
- Delete(Result,i,1)
|
|
|
|
- else
|
|
|
|
- inc(i);
|
|
|
|
- end;
|
|
|
|
|
|
+ if Result[1]='$' then
|
|
|
|
+ // hexadecimal -> can not be a float, 'E' is a hexdigit
|
|
|
|
+ while i<length(Result) do
|
|
|
|
+ begin
|
|
|
|
+ if (Result[i]='0') and (Result[i+1] in ['0'..'9','A'..'F','a'..'f'])
|
|
|
|
+ and ((i=1) or not (Result[i-1] in ['0'..'9','A'..'F','a'..'f'])) then
|
|
|
|
+ Delete(Result,i,1)
|
|
|
|
+ else
|
|
|
|
+ inc(i);
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ // decimal, can be a float, 'E' is a start of a new number
|
|
|
|
+ while i<length(Result) do
|
|
|
|
+ begin
|
|
|
|
+ if (Result[i]='0') and (Result[i+1] in ['0'..'9'])
|
|
|
|
+ and ((i=1) or not (Result[i-1] in ['.','0'..'9'])) then
|
|
|
|
+ Delete(Result,i,1)
|
|
|
|
+ else
|
|
|
|
+ inc(i);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -6338,7 +6354,8 @@ begin
|
|
// number was rounded -> we lost precision
|
|
// number was rounded -> we lost precision
|
|
DoError(20161024230812,nInvalidNumber,sInvalidNumber,[El.Value],El);
|
|
DoError(20161024230812,nInvalidNumber,sInvalidNumber,[El.Value],El);
|
|
L:=CreateLiteralNumber(El,Number);
|
|
L:=CreateLiteralNumber(El,Number);
|
|
- S:=DeleteLeadingZeroes(copy(El.Value,2,length(El.Value)));
|
|
|
|
|
|
+ S:=DeleteLeadingZeroes(El.Value);
|
|
|
|
+ S:=copy(S,2,length(S));
|
|
case El.Value[1] of
|
|
case El.Value[1] of
|
|
'$': S:='0x'+S;
|
|
'$': S:='0x'+S;
|
|
'&': if TargetProcessor=ProcessorECMAScript5 then
|
|
'&': if TargetProcessor=ProcessorECMAScript5 then
|