fcl-js: added TJSUnaryBracketsExpression, needed for (function(){})

git-svn-id: trunk@41358 -
This commit is contained in:
Mattias Gaertner 2019-02-17 20:42:14 +00:00
parent 0a228b9115
commit 34515b09cf
2 changed files with 45 additions and 17 deletions

View File

@ -439,6 +439,13 @@ Type
Class function PostFixOperatorToken : tjsToken; override;
end;
{ TJSUnaryBracketsExpression - e.g. '(A)' }
TJSUnaryBracketsExpression = Class(TJSUnaryExpression)
Public
Class function PrefixOperatorToken : tjsToken; override;
Class function PostFixOperatorToken : tjsToken; override;
end;
{ TJSBinary - base class }
@ -1432,6 +1439,18 @@ begin
Result:=tjsThrow;
end;
{ TJSUnaryBracketsExpression }
class function TJSUnaryBracketsExpression.PrefixOperatorToken: tjsToken;
begin
Result:=tjsBraceOpen;
end;
class function TJSUnaryBracketsExpression.PostFixOperatorToken: tjsToken;
begin
Result:=tjsBraceClose;
end;
{ TJSUnaryPostMinusMinusExpression }
Class function TJSUnaryPostMinusMinusExpression.PostFixOperatorToken : tjsToken;

View File

@ -240,7 +240,9 @@ Type
Property Options : TWriteOptions Read FOptions Write SetOptions;
Property IndentSize : Byte Read FIndentSize Write FIndentSize;
Property UseUTF8 : Boolean Read GetUseUTF8;
property LastChar: WideChar read FLastChar;
Property LastChar: WideChar read FLastChar;
Property SkipCurlyBrackets : Boolean read FSkipCurlyBrackets write FSkipCurlyBrackets;
Property SkipRoundBrackets : Boolean read FSkipRoundBrackets write FSkipRoundBrackets;
end;
EJSWriter = Class(Exception);
@ -944,10 +946,14 @@ begin
and (not (A is TJSSourceElements))
and (not (A is TJSEmptyBlockStatement))
then
begin
if FLastChar<>';' then
Write(';');
if C then
Write('; ')
Write(' ')
else
Writeln(';');
Writeln('');
end;
end;
Writer.CurElement:=LastEl;
if C then
@ -1197,17 +1203,15 @@ begin
Write(S);
end;
WriteJS(El.A);
if (S='') then
S:=El.PostFixOperator;
if (S<>'') then
begin
S:=El.PostFixOperator;
if (S<>'') then
begin
Writer.CurElement:=El;
if ((S='-') and (FLastChar='-'))
or ((S='+') and (FLastChar='+')) then
Write(' ');
Write(S);
end;
Writer.CurElement:=El;
case S[1] of
'+': if FLastChar='+' then Write(' ');
'-': if FLastChar='-' then Write(' ');
end;
Write(S);
end;
end;
@ -1240,10 +1244,12 @@ begin
begin
if not (LastEl is TJSStatementList) then
begin
if FLastChar<>';' then
Write(';');
if C then
Write('; ')
Write(' ')
else
Writeln(';');
Writeln('');
end;
FSkipCurlyBrackets:=True;
WriteJS(El.B);
@ -1252,11 +1258,14 @@ begin
if (not C) and not (LastEl is TJSStatementList) then
writeln(';');
end
else if Assigned(El.B) then
else if Assigned(El.B) and not IsEmptyStatement(El.B) then
begin
WriteJS(El.B);
if (not C) and not (El.B is TJSStatementList) then
writeln(';');
if FLastChar=';' then
writeln('')
else
writeln(';');
end;
if B then
begin