diff --git a/compiler/packages/pastojs/src/fppas2js.pp b/compiler/packages/pastojs/src/fppas2js.pp index d31accf..6cf3435 100644 --- a/compiler/packages/pastojs/src/fppas2js.pp +++ b/compiler/packages/pastojs/src/fppas2js.pp @@ -8185,7 +8185,8 @@ begin RemoveFromSourceElements(Src,ImplVarSt); // remove unneeded $mod.$implcode = function(){} RemoveFromSourceElements(Src,AssignSt); - HasImplUsesClause:=length(El.ImplementationSection.UsesClause)>0; + HasImplUsesClause:=(El.ImplementationSection<>nil) + and (length(El.ImplementationSection.UsesClause)>0); end else begin @@ -15235,6 +15236,7 @@ Var SectionScope: TPas2JSSectionScope; SectionCtx: TSectionContext; Src: TJSSourceElements; + ImplSect: TImplementationSection; begin SectionScope:=Section.CustomData as TPas2JSSectionScope; AContext.ScannerBoolSwitches:=SectionScope.BoolSwitches; @@ -15253,8 +15255,9 @@ Var InitForwards(Section.Declarations,TSectionContext(AContext)); if Section is TInterfaceSection then begin - InitForwards(TPasModule(Section.Parent).ImplementationSection.Declarations, - TSectionContext(AContext)); + ImplSect:=TPasModule(Section.Parent).ImplementationSection; + if ImplSect<>nil then + InitForwards(ImplSect.Declarations,TSectionContext(AContext)); end; end; end; @@ -17558,9 +17561,12 @@ begin end; // create implementation declarations - ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext); - if ImplDecl<>nil then - RaiseInconsistency(20170910175032,El); // elements should have been added directly + if El.ImplementationSection<>nil then + begin + ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext); + if ImplDecl<>nil then + RaiseInconsistency(20170910175032,El); // elements should have been added directly + end; IntfContext.ImplHeaderIndex:=ImplContext.HeaderIndex; Result:=FunDecl; finally diff --git a/compiler/packages/pastojs/src/pas2jsfiler.pp b/compiler/packages/pastojs/src/pas2jsfiler.pp index dae0698..f47269a 100644 --- a/compiler/packages/pastojs/src/pas2jsfiler.pp +++ b/compiler/packages/pastojs/src/pas2jsfiler.pp @@ -8197,12 +8197,16 @@ var aModule: TPasModule; function CreateOrContinueSection(const PropName: string; var Section: TPasSection; - SectionClass: TPasSectionClass): boolean; + SectionClass: TPasSectionClass; MustExist: boolean): boolean; var SubObj: TJSONObject; begin if not ReadObject(Obj,PropName,SubObj,aModule) then - RaiseMsg(20180308142146,aModule); + begin + if MustExist then + RaiseMsg(20180308142146,aModule); + exit; + end; if Section=nil then Section:=TPasSection(CreateElement(SectionClass,'',aModule)); ReadSection(SubObj,Section,aContext); @@ -8256,7 +8260,7 @@ begin // start or continue ProgramSection Prog:=TPasProgram(aModule); if not CreateOrContinueSection('Program',TPasSection(Prog.ProgramSection), - TProgramSection) then + TProgramSection,true) then exit; // pending uses interfaces -> pause end else if aModule.ClassType=TPasLibrary then @@ -8264,7 +8268,7 @@ begin // start or continue LibrarySection Lib:=TPasLibrary(aModule); if not CreateOrContinueSection('Library',TPasSection(Lib.LibrarySection), - TLibrarySection) then + TLibrarySection,true) then exit; // pending uses interfaces -> pause end else @@ -8274,12 +8278,12 @@ begin begin // start or continue unit Interface if not CreateOrContinueSection('Interface',TPasSection(aModule.InterfaceSection), - TInterfaceSection) then + TInterfaceSection,true) then exit; // pending uses interfaces -> pause end; // start or continue unit Implementation if not CreateOrContinueSection('Implementation',TPasSection(aModule.ImplementationSection), - TImplementationSection) then + TImplementationSection,false) then exit; // pending uses interfaces -> pause end; if (Obj.Find('Init')<>nil) diff --git a/compiler/packages/pastojs/tests/tcprecompile.pas b/compiler/packages/pastojs/tests/tcprecompile.pas index 01c3027..aa88a2e 100644 --- a/compiler/packages/pastojs/tests/tcprecompile.pas +++ b/compiler/packages/pastojs/tests/tcprecompile.pas @@ -54,6 +54,7 @@ type TTestCLI_Precompile = class(TCustomTestCLI_Precompile) published procedure TestPCU_EmptyUnit; + procedure TestPCU_UnitWithoutImplementation; procedure TestPCU_UTF8BOM; procedure TestPCU_ParamNS; procedure TestPCU_Overloads; @@ -173,6 +174,25 @@ begin CheckPrecompile('test1.pas','src'); 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; var aFile: TCLIFile;