|
@@ -1982,8 +1982,17 @@ var
|
|
InitName: String;
|
|
InitName: String;
|
|
LastNode: TJSElement;
|
|
LastNode: TJSElement;
|
|
Arg: TJSArrayLiteralElement;
|
|
Arg: TJSArrayLiteralElement;
|
|
|
|
+ IsProg, IsLib: Boolean;
|
|
begin
|
|
begin
|
|
if SkipTests then exit;
|
|
if SkipTests then exit;
|
|
|
|
+
|
|
|
|
+ IsProg:=false;
|
|
|
|
+ IsLib:=false;
|
|
|
|
+ if Module is TPasProgram then
|
|
|
|
+ IsProg:=true
|
|
|
|
+ else if Module is TPasLibrary then
|
|
|
|
+ IsLib:=true;
|
|
|
|
+
|
|
try
|
|
try
|
|
FJSModule:=FConverter.ConvertPasElement(Module,Engine) as TJSSourceElements;
|
|
FJSModule:=FConverter.ConvertPasElement(Module,Engine) as TJSSourceElements;
|
|
except
|
|
except
|
|
@@ -2018,9 +2027,9 @@ begin
|
|
AssertNotNull('module name param',Arg.Expr);
|
|
AssertNotNull('module name param',Arg.Expr);
|
|
ModuleNameExpr:=Arg.Expr as TJSLiteral;
|
|
ModuleNameExpr:=Arg.Expr as TJSLiteral;
|
|
AssertEquals('module name param is string',ord(jstString),ord(ModuleNameExpr.Value.ValueType));
|
|
AssertEquals('module name param is string',ord(jstString),ord(ModuleNameExpr.Value.ValueType));
|
|
- if Module is TPasProgram then
|
|
|
|
|
|
+ if IsProg then
|
|
AssertEquals('module name','program',String(ModuleNameExpr.Value.AsString))
|
|
AssertEquals('module name','program',String(ModuleNameExpr.Value.AsString))
|
|
- else if Module is TPasLibrary then
|
|
|
|
|
|
+ else if IsLib then
|
|
AssertEquals('module name','library',String(ModuleNameExpr.Value.AsString))
|
|
AssertEquals('module name','library',String(ModuleNameExpr.Value.AsString))
|
|
else
|
|
else
|
|
AssertEquals('module name',Module.Name,String(ModuleNameExpr.Value.AsString));
|
|
AssertEquals('module name',Module.Name,String(ModuleNameExpr.Value.AsString));
|
|
@@ -2038,13 +2047,15 @@ begin
|
|
CheckFunctionParam('module intf-function',Arg,FJSModuleSrc);
|
|
CheckFunctionParam('module intf-function',Arg,FJSModuleSrc);
|
|
|
|
|
|
// search for $mod.$init or $mod.$main - the last statement
|
|
// search for $mod.$init or $mod.$main - the last statement
|
|
- if (Module is TPasProgram) or (Module is TPasLibrary) then
|
|
|
|
|
|
+ if IsProg or IsLib then
|
|
begin
|
|
begin
|
|
InitName:='$main';
|
|
InitName:='$main';
|
|
AssertEquals('$mod.'+InitName+' function 1',true,JSModuleSrc.Statements.Count>0);
|
|
AssertEquals('$mod.'+InitName+' function 1',true,JSModuleSrc.Statements.Count>0);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
InitName:='$init';
|
|
InitName:='$init';
|
|
|
|
+ InitAssign:=nil;
|
|
|
|
+ InitFunction:=nil;
|
|
FJSInitBody:=nil;
|
|
FJSInitBody:=nil;
|
|
if JSModuleSrc.Statements.Count>0 then
|
|
if JSModuleSrc.Statements.Count>0 then
|
|
begin
|
|
begin
|
|
@@ -2057,7 +2068,7 @@ begin
|
|
InitFunction:=InitAssign.Expr as TJSFunctionDeclarationStatement;
|
|
InitFunction:=InitAssign.Expr as TJSFunctionDeclarationStatement;
|
|
FJSInitBody:=InitFunction.AFunction.Body as TJSFunctionBody;
|
|
FJSInitBody:=InitFunction.AFunction.Body as TJSFunctionBody;
|
|
end
|
|
end
|
|
- else if (Module is TPasProgram) or (Module is TPasLibrary) then
|
|
|
|
|
|
+ else if IsProg or IsLib then
|
|
CheckDottedIdentifier('init function',InitAssign.LHS,'$mod.'+InitName);
|
|
CheckDottedIdentifier('init function',InitAssign.LHS,'$mod.'+InitName);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -2125,6 +2136,7 @@ procedure TCustomTestModule.CheckSource(Msg, Statements: String;
|
|
InitStatements: string; ImplStatements: string);
|
|
InitStatements: string; ImplStatements: string);
|
|
var
|
|
var
|
|
ActualSrc, ExpectedSrc, InitName: String;
|
|
ActualSrc, ExpectedSrc, InitName: String;
|
|
|
|
+ IsProg, IsLib: Boolean;
|
|
begin
|
|
begin
|
|
ActualSrc:=JSToStr(JSModuleSrc);
|
|
ActualSrc:=JSToStr(JSModuleSrc);
|
|
if coUseStrict in Converter.Options then
|
|
if coUseStrict in Converter.Options then
|
|
@@ -2142,9 +2154,15 @@ begin
|
|
+'};'+LineEnding;
|
|
+'};'+LineEnding;
|
|
|
|
|
|
// program main or unit initialization
|
|
// program main or unit initialization
|
|
- if (Module is TPasProgram) or (Trim(InitStatements)<>'') then
|
|
|
|
|
|
+ IsProg:=false;
|
|
|
|
+ IsLib:=false;
|
|
|
|
+ if Module is TPasProgram then
|
|
|
|
+ IsProg:=true
|
|
|
|
+ else if Module is TPasLibrary then
|
|
|
|
+ IsLib:=true;
|
|
|
|
+ if IsProg or IsLib or (Trim(InitStatements)<>'') then
|
|
begin
|
|
begin
|
|
- if (Module is TPasProgram) or (Module is TPasLibrary) then
|
|
|
|
|
|
+ if IsProg or IsLib then
|
|
InitName:='$main'
|
|
InitName:='$main'
|
|
else
|
|
else
|
|
InitName:='$init';
|
|
InitName:='$init';
|
|
@@ -2156,6 +2174,7 @@ begin
|
|
|
|
|
|
//writeln('TCustomTestModule.CheckSource ExpectedIntf="',ExpectedSrc,'"');
|
|
//writeln('TCustomTestModule.CheckSource ExpectedIntf="',ExpectedSrc,'"');
|
|
//writeln('TTestModule.CheckSource InitStatements="',Trim(InitStatements),'"');
|
|
//writeln('TTestModule.CheckSource InitStatements="',Trim(InitStatements),'"');
|
|
|
|
+ //writeln('TCustomTestModule.CheckSource ',ActualSrc);
|
|
CheckDiff(Msg,ExpectedSrc,ActualSrc);
|
|
CheckDiff(Msg,ExpectedSrc,ActualSrc);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -33777,8 +33796,6 @@ end;
|
|
|
|
|
|
procedure TTestModule.TestLibrary_ExportFunc;
|
|
procedure TTestModule.TestLibrary_ExportFunc;
|
|
begin
|
|
begin
|
|
- exit;
|
|
|
|
-
|
|
|
|
StartLibrary(false);
|
|
StartLibrary(false);
|
|
Add([
|
|
Add([
|
|
'procedure Run(w: word);',
|
|
'procedure Run(w: word);',
|
|
@@ -33791,6 +33808,8 @@ begin
|
|
ConvertLibrary;
|
|
ConvertLibrary;
|
|
CheckSource('TestLibrary_ExportFunc',
|
|
CheckSource('TestLibrary_ExportFunc',
|
|
LinesToStr([ // statements
|
|
LinesToStr([ // statements
|
|
|
|
+ 'this.Run = function (w) {',
|
|
|
|
+ '};',
|
|
'']),
|
|
'']),
|
|
LinesToStr([
|
|
LinesToStr([
|
|
'']));
|
|
'']));
|