mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-25 10:59:06 +02:00
pastojs: fixed unit without implementation
This commit is contained in:
parent
648a86be7e
commit
91e7558f0f
@ -8185,7 +8185,8 @@ begin
|
|||||||
RemoveFromSourceElements(Src,ImplVarSt);
|
RemoveFromSourceElements(Src,ImplVarSt);
|
||||||
// remove unneeded $mod.$implcode = function(){}
|
// remove unneeded $mod.$implcode = function(){}
|
||||||
RemoveFromSourceElements(Src,AssignSt);
|
RemoveFromSourceElements(Src,AssignSt);
|
||||||
HasImplUsesClause:=length(El.ImplementationSection.UsesClause)>0;
|
HasImplUsesClause:=(El.ImplementationSection<>nil)
|
||||||
|
and (length(El.ImplementationSection.UsesClause)>0);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -15235,6 +15236,7 @@ Var
|
|||||||
SectionScope: TPas2JSSectionScope;
|
SectionScope: TPas2JSSectionScope;
|
||||||
SectionCtx: TSectionContext;
|
SectionCtx: TSectionContext;
|
||||||
Src: TJSSourceElements;
|
Src: TJSSourceElements;
|
||||||
|
ImplSect: TImplementationSection;
|
||||||
begin
|
begin
|
||||||
SectionScope:=Section.CustomData as TPas2JSSectionScope;
|
SectionScope:=Section.CustomData as TPas2JSSectionScope;
|
||||||
AContext.ScannerBoolSwitches:=SectionScope.BoolSwitches;
|
AContext.ScannerBoolSwitches:=SectionScope.BoolSwitches;
|
||||||
@ -15253,8 +15255,9 @@ Var
|
|||||||
InitForwards(Section.Declarations,TSectionContext(AContext));
|
InitForwards(Section.Declarations,TSectionContext(AContext));
|
||||||
if Section is TInterfaceSection then
|
if Section is TInterfaceSection then
|
||||||
begin
|
begin
|
||||||
InitForwards(TPasModule(Section.Parent).ImplementationSection.Declarations,
|
ImplSect:=TPasModule(Section.Parent).ImplementationSection;
|
||||||
TSectionContext(AContext));
|
if ImplSect<>nil then
|
||||||
|
InitForwards(ImplSect.Declarations,TSectionContext(AContext));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -17558,9 +17561,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// create implementation declarations
|
// create implementation declarations
|
||||||
ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext);
|
if El.ImplementationSection<>nil then
|
||||||
if ImplDecl<>nil then
|
begin
|
||||||
RaiseInconsistency(20170910175032,El); // elements should have been added directly
|
ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext);
|
||||||
|
if ImplDecl<>nil then
|
||||||
|
RaiseInconsistency(20170910175032,El); // elements should have been added directly
|
||||||
|
end;
|
||||||
IntfContext.ImplHeaderIndex:=ImplContext.HeaderIndex;
|
IntfContext.ImplHeaderIndex:=ImplContext.HeaderIndex;
|
||||||
Result:=FunDecl;
|
Result:=FunDecl;
|
||||||
finally
|
finally
|
||||||
|
@ -8197,12 +8197,16 @@ var
|
|||||||
aModule: TPasModule;
|
aModule: TPasModule;
|
||||||
|
|
||||||
function CreateOrContinueSection(const PropName: string; var Section: TPasSection;
|
function CreateOrContinueSection(const PropName: string; var Section: TPasSection;
|
||||||
SectionClass: TPasSectionClass): boolean;
|
SectionClass: TPasSectionClass; MustExist: boolean): boolean;
|
||||||
var
|
var
|
||||||
SubObj: TJSONObject;
|
SubObj: TJSONObject;
|
||||||
begin
|
begin
|
||||||
if not ReadObject(Obj,PropName,SubObj,aModule) then
|
if not ReadObject(Obj,PropName,SubObj,aModule) then
|
||||||
RaiseMsg(20180308142146,aModule);
|
begin
|
||||||
|
if MustExist then
|
||||||
|
RaiseMsg(20180308142146,aModule);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
if Section=nil then
|
if Section=nil then
|
||||||
Section:=TPasSection(CreateElement(SectionClass,'',aModule));
|
Section:=TPasSection(CreateElement(SectionClass,'',aModule));
|
||||||
ReadSection(SubObj,Section,aContext);
|
ReadSection(SubObj,Section,aContext);
|
||||||
@ -8256,7 +8260,7 @@ begin
|
|||||||
// start or continue ProgramSection
|
// start or continue ProgramSection
|
||||||
Prog:=TPasProgram(aModule);
|
Prog:=TPasProgram(aModule);
|
||||||
if not CreateOrContinueSection('Program',TPasSection(Prog.ProgramSection),
|
if not CreateOrContinueSection('Program',TPasSection(Prog.ProgramSection),
|
||||||
TProgramSection) then
|
TProgramSection,true) then
|
||||||
exit; // pending uses interfaces -> pause
|
exit; // pending uses interfaces -> pause
|
||||||
end
|
end
|
||||||
else if aModule.ClassType=TPasLibrary then
|
else if aModule.ClassType=TPasLibrary then
|
||||||
@ -8264,7 +8268,7 @@ begin
|
|||||||
// start or continue LibrarySection
|
// start or continue LibrarySection
|
||||||
Lib:=TPasLibrary(aModule);
|
Lib:=TPasLibrary(aModule);
|
||||||
if not CreateOrContinueSection('Library',TPasSection(Lib.LibrarySection),
|
if not CreateOrContinueSection('Library',TPasSection(Lib.LibrarySection),
|
||||||
TLibrarySection) then
|
TLibrarySection,true) then
|
||||||
exit; // pending uses interfaces -> pause
|
exit; // pending uses interfaces -> pause
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -8274,12 +8278,12 @@ begin
|
|||||||
begin
|
begin
|
||||||
// start or continue unit Interface
|
// start or continue unit Interface
|
||||||
if not CreateOrContinueSection('Interface',TPasSection(aModule.InterfaceSection),
|
if not CreateOrContinueSection('Interface',TPasSection(aModule.InterfaceSection),
|
||||||
TInterfaceSection) then
|
TInterfaceSection,true) then
|
||||||
exit; // pending uses interfaces -> pause
|
exit; // pending uses interfaces -> pause
|
||||||
end;
|
end;
|
||||||
// start or continue unit Implementation
|
// start or continue unit Implementation
|
||||||
if not CreateOrContinueSection('Implementation',TPasSection(aModule.ImplementationSection),
|
if not CreateOrContinueSection('Implementation',TPasSection(aModule.ImplementationSection),
|
||||||
TImplementationSection) then
|
TImplementationSection,false) then
|
||||||
exit; // pending uses interfaces -> pause
|
exit; // pending uses interfaces -> pause
|
||||||
end;
|
end;
|
||||||
if (Obj.Find('Init')<>nil)
|
if (Obj.Find('Init')<>nil)
|
||||||
|
@ -54,6 +54,7 @@ type
|
|||||||
TTestCLI_Precompile = class(TCustomTestCLI_Precompile)
|
TTestCLI_Precompile = class(TCustomTestCLI_Precompile)
|
||||||
published
|
published
|
||||||
procedure TestPCU_EmptyUnit;
|
procedure TestPCU_EmptyUnit;
|
||||||
|
procedure TestPCU_UnitWithoutImplementation;
|
||||||
procedure TestPCU_UTF8BOM;
|
procedure TestPCU_UTF8BOM;
|
||||||
procedure TestPCU_ParamNS;
|
procedure TestPCU_ParamNS;
|
||||||
procedure TestPCU_Overloads;
|
procedure TestPCU_Overloads;
|
||||||
@ -173,6 +174,25 @@ begin
|
|||||||
CheckPrecompile('test1.pas','src');
|
CheckPrecompile('test1.pas','src');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestCLI_Precompile.TestPCU_UnitWithoutImplementation;
|
||||||
|
begin
|
||||||
|
AddUnit('src/system.pp',[''],['']);
|
||||||
|
AddFile('src/unit1.pas',
|
||||||
|
'unit unit1;'+LineEnding
|
||||||
|
+'interface'+LineEnding
|
||||||
|
+'end.'+LineEnding);
|
||||||
|
AddFile('src/unit2.pas',
|
||||||
|
'unit unit2;'+LineEnding
|
||||||
|
+'interface'+LineEnding
|
||||||
|
+'uses unit1;'+LineEnding
|
||||||
|
+'end.'+LineEnding);
|
||||||
|
AddFile('test1.pas',[
|
||||||
|
'uses unit2;',
|
||||||
|
'begin',
|
||||||
|
'end.']);
|
||||||
|
CheckPrecompile('test1.pas','src');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestCLI_Precompile.TestPCU_UTF8BOM;
|
procedure TTestCLI_Precompile.TestPCU_UTF8BOM;
|
||||||
var
|
var
|
||||||
aFile: TCLIFile;
|
aFile: TCLIFile;
|
||||||
|
Loading…
Reference in New Issue
Block a user