pastojs: fixed if then asm a;b end

git-svn-id: trunk@48231 -
This commit is contained in:
Mattias Gaertner 2021-01-20 20:24:38 +00:00
parent 62edfa5584
commit eaa519209e
2 changed files with 71 additions and 0 deletions

View File

@ -3954,6 +3954,7 @@ var
begin
Lines:=El.Tokens;
if Lines=nil then exit;
// ToDo: resolve explicit references
end;
procedure TPas2JSResolver.ResolveNameExpr(El: TPasExpr; const aName: string;
@ -17551,6 +17552,7 @@ var
L: TJSLiteral;
AsmLines: TStrings;
Line, Col, StartLine: integer;
Statements: TJSStatementList;
begin
if AContext=nil then ;
AsmLines:=El.Tokens;
@ -17569,6 +17571,15 @@ begin
L:=TJSLiteral.Create(Line+StartLine,Col,El.SourceFilename);
L.Value.CustomValue:=TJSString(s);
Result:=L;
if Pos(';',s)>0 then
begin
// multi statement JS
// for example "if e then asm a;b end;"
// -> if (e){ a;b }
Statements:=TJSStatementList.Create(L.Line,L.Column,L.Source);
Statements.A:=L;
Result:=Statements;
end;
end;
end;

View File

@ -337,6 +337,7 @@ type
Procedure TestProc_External;
Procedure TestProc_ExternalOtherUnit;
Procedure TestProc_Asm;
Procedure TestProc_AsmSubBlock;
Procedure TestProc_Assembler;
Procedure TestProc_VarParam;
Procedure TestProc_VarParamString;
@ -4139,6 +4140,65 @@ begin
]));
end;
procedure TTestModule.TestProc_AsmSubBlock;
begin
StartProgram(true,[supTObject]);
Add([
'{$mode delphi}',
'type',
' TBird = class end;',
'procedure Run(w: word);',
'begin;',
' if true then asm console.log(); end;',
' if w>3 then asm',
' var a = w+1;',
' w = a+3;',
' end;',
' while (w>7) do asm',
' w+=3; w*=2;',
' end;',
' try',
' except',
' on E: TBird do',
' asm console.log(E); end;',
' on E: TObject do',
' asm var i=3; i--; end;',
' else asm Fly; High; end;',
' end;',
'end;',
'begin']);
ConvertProgram;
CheckSource('TestProc_AsmSubBlock',
LinesToStr([ // statements
'rtl.createClass(this, "TBird", pas.system.TObject, function () {',
'});',
'this.Run = function (w) {',
' if (true) console.log();',
' if (w > 3) {',
' var a = w+1;',
' w = a+3;',
' };',
' while (w > 7) {',
' w+=3; w*=2;',
' };',
' try {} catch ($e) {',
' if ($mod.TBird.isPrototypeOf($e)) {',
' var E = $e;',
' console.log(E);',
' } else if (pas.system.TObject.isPrototypeOf($e)) {',
' var E = $e;',
' var i=3; i--;',
' } else {',
' Fly; High;',
' }',
' };',
'};',
'']),
LinesToStr([
''
]));
end;
procedure TTestModule.TestProc_Assembler;
begin
StartProgram(false);