mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-16 08:59:26 +02:00
fcl-js: write async function and await expression
git-svn-id: trunk@45423 -
This commit is contained in:
parent
8e8bbf4411
commit
a7ecde8bb2
@ -48,7 +48,8 @@ type
|
||||
tjsSWITCH,
|
||||
tjsTHIS, tjsTHROW, tjsTrue, tjsTRY, tjsTYPEOF,
|
||||
tjsVAR, tjsVOID,
|
||||
tjsWHILE, tjsWITH
|
||||
tjsWHILE, tjsWITH,
|
||||
tjsAWAIT
|
||||
);
|
||||
|
||||
const
|
||||
@ -83,7 +84,8 @@ const
|
||||
'switch',
|
||||
'this', 'throw', 'true', 'try', 'typeof',
|
||||
'var', 'void',
|
||||
'while', 'with'
|
||||
'while', 'with',
|
||||
'await'
|
||||
);
|
||||
|
||||
|
||||
|
@ -126,6 +126,7 @@ Type
|
||||
TJSFuncDef = Class(TJSObject)
|
||||
private
|
||||
FBody: TJSFunctionBody;
|
||||
FIsAsync: Boolean;
|
||||
FIsEmpty: Boolean;
|
||||
FName: TJSString;
|
||||
FParams: TStrings;
|
||||
@ -137,6 +138,7 @@ Type
|
||||
Property Body : TJSFunctionBody Read FBody Write FBody; // can be nil
|
||||
Property Name : TJSString Read FName Write FName;
|
||||
Property IsEmpty : Boolean Read FIsEmpty Write FIsEmpty;
|
||||
Property IsAsync : Boolean Read FIsAsync Write FIsAsync;
|
||||
end;
|
||||
|
||||
{ TJSElement }
|
||||
@ -383,6 +385,13 @@ Type
|
||||
Class function PrefixOperatorToken : tjsToken; override;
|
||||
end;
|
||||
|
||||
{ TJSAwaitExpression - e.g. 'await A' }
|
||||
|
||||
TJSAwaitExpression = Class(TJSUnaryExpression)
|
||||
Public
|
||||
Class function PrefixOperatorToken : tjsToken; Override;
|
||||
end;
|
||||
|
||||
{ TJSUnaryPrePlusPlusExpression - e.g. '++A' }
|
||||
|
||||
TJSUnaryPrePlusPlusExpression = Class(TJSUnaryExpression)
|
||||
@ -1514,6 +1523,13 @@ begin
|
||||
Result:=tjsTypeOf;
|
||||
end;
|
||||
|
||||
{ TJSAwaitExpression }
|
||||
|
||||
class function TJSAwaitExpression.PrefixOperatorToken: tjsToken;
|
||||
begin
|
||||
Result:=tjsAwait;
|
||||
end;
|
||||
|
||||
{ TJSUnaryDeleteExpression }
|
||||
|
||||
Class function TJSUnaryDeleteExpression.PrefixOperatorToken : tjsToken;
|
||||
@ -1705,7 +1721,7 @@ begin
|
||||
else
|
||||
begin
|
||||
Result:=TokenInfos[t];
|
||||
if t in [tjsTypeOf,tjsVoid,tjsDelete,tjsThrow] then
|
||||
if t in [tjsTypeOf,tjsVoid,tjsDelete,tjsThrow,tjsAwait] then
|
||||
Result:=Result+' ';
|
||||
end;
|
||||
end;
|
||||
|
@ -927,6 +927,8 @@ Var
|
||||
begin
|
||||
LastEl:=Writer.CurElement;
|
||||
C:=(woCompact in Options);
|
||||
if fd.IsAsync then
|
||||
Write('async ');
|
||||
Write('function ');
|
||||
If (FD.Name<>'') then
|
||||
Write(FD.Name);
|
||||
|
@ -167,6 +167,7 @@ type
|
||||
Procedure TestFunctionDefBody1Compact;
|
||||
Procedure TestFunctionDefBody2;
|
||||
Procedure TestFunctionDefBody2Compact;
|
||||
Procedure TestFunctionDefAsync;
|
||||
Procedure TestTryCatch;
|
||||
Procedure TestTryCatchCompact;
|
||||
Procedure TestTryFinally;
|
||||
@ -193,6 +194,7 @@ type
|
||||
Procedure TestUnaryDelete;
|
||||
Procedure TestUnaryVoid;
|
||||
Procedure TestUnaryTypeOf;
|
||||
Procedure TestUnaryAwait;
|
||||
Procedure TestPrefixPlusPLus;
|
||||
Procedure TestPrefixMinusMinus;
|
||||
Procedure TestUnaryMinus;
|
||||
@ -347,6 +349,11 @@ begin
|
||||
TestUnary('typeof expresssion',TJSUnaryTypeOfExpression,'typeof a');
|
||||
end;
|
||||
|
||||
procedure TTestExpressionWriter.TestUnaryAwait;
|
||||
begin
|
||||
TestUnary('await expresssion',TJSAwaitExpression,'await a');
|
||||
end;
|
||||
|
||||
procedure TTestExpressionWriter.TestPrefixPlusPLus;
|
||||
begin
|
||||
TestUnary('prefix ++ expresssion',TJSUnaryPrePlusPlusExpression,'++a');
|
||||
@ -1902,6 +1909,21 @@ begin
|
||||
AssertWrite('Function, 2 statements, compact','function a(b) {b=b*10; return b}',FD);
|
||||
end;
|
||||
|
||||
procedure TTestStatementWriter.TestFunctionDefAsync;
|
||||
|
||||
Var
|
||||
FD : TJSFunctionDeclarationStatement;
|
||||
|
||||
begin
|
||||
FD:=TJSFunctionDeclarationStatement.Create(0,0);
|
||||
FD.AFunction:=TJSFuncDef.Create;
|
||||
FD.AFunction.IsAsync:=true;
|
||||
FD.AFunction.Name:='a';
|
||||
AssertWrite('Async function',
|
||||
'async function a() {'+sLineBreak
|
||||
+'}',FD);
|
||||
end;
|
||||
|
||||
procedure TTestStatementWriter.TestTryCatch;
|
||||
|
||||
Var
|
||||
|
Loading…
Reference in New Issue
Block a user