Browse Source

pastojs: library: export var

mattias 3 years ago
parent
commit
d2a091ef85
2 changed files with 21 additions and 8 deletions
  1. 15 6
      packages/pastojs/src/fppas2js.pp
  2. 6 2
      packages/pastojs/tests/tcmodules.pas

+ 15 - 6
packages/pastojs/src/fppas2js.pp

@@ -4915,6 +4915,7 @@ var
   ResolvedEl: TPasResolverResult;
   ResolvedEl: TPasResolverResult;
   DeclEl: TPasElement;
   DeclEl: TPasElement;
   Proc: TPasProcedure;
   Proc: TPasProcedure;
+  V: TPasVariable;
 begin
 begin
   if El.Parent is TLibrarySection then
   if El.Parent is TLibrarySection then
     // ok
     // ok
@@ -4930,14 +4931,22 @@ begin
   DeclEl:=ResolvedEl.IdentEl;
   DeclEl:=ResolvedEl.IdentEl;
   if DeclEl=nil then
   if DeclEl=nil then
     RaiseMsg(20210106223620,nSymbolCannotBeExportedFromALibrary,
     RaiseMsg(20210106223620,nSymbolCannotBeExportedFromALibrary,
-      sSymbolCannotBeExportedFromALibrary,[],El)
-  else if DeclEl is TPasProcedure then
+      sSymbolCannotBeExportedFromALibrary,[],El);
+  if not (DeclEl.Parent is TPasSection) then
+    RaiseMsg(20210106224436,nSymbolCannotBeExportedFromALibrary,
+      sSymbolCannotBeExportedFromALibrary,[],El);
+  if DeclEl is TPasProcedure then
     begin
     begin
     Proc:=TPasProcedure(DeclEl);
     Proc:=TPasProcedure(DeclEl);
-    if Proc.Parent is TPasSection then
-      // ok
-    else
-      RaiseMsg(20210106224436,nSymbolCannotBeExportedFromALibrary,
+    if Proc.IsExternal or Proc.IsAbstract then
+      RaiseMsg(20211021225630,nSymbolCannotBeExportedFromALibrary,
+        sSymbolCannotBeExportedFromALibrary,[],El);
+    end
+  else if DeclEl is TPasVariable then
+    begin
+    V:=TPasVariable(DeclEl);
+    if vmExternal in V.VarModifiers then
+      RaiseMsg(20211021225634,nSymbolCannotBeExportedFromALibrary,
         sSymbolCannotBeExportedFromALibrary,[],El);
         sSymbolCannotBeExportedFromALibrary,[],El);
     end
     end
   else
   else

+ 6 - 2
packages/pastojs/tests/tcmodules.pas

@@ -913,6 +913,7 @@ type
     Procedure TestLibrary_ExportFunc;
     Procedure TestLibrary_ExportFunc;
     Procedure TestLibrary_Export_Index_Fail;
     Procedure TestLibrary_Export_Index_Fail;
     Procedure TestLibrary_ExportVar; // ToDo
     Procedure TestLibrary_ExportVar; // ToDo
+    Procedure TestLibrary_ExportUnitFunc;
     // ToDo: test delayed specialization init
     // ToDo: test delayed specialization init
     // ToDo: analyzer
     // ToDo: analyzer
   end;
   end;
@@ -33836,8 +33837,6 @@ end;
 
 
 procedure TTestModule.TestLibrary_ExportVar;
 procedure TTestModule.TestLibrary_ExportVar;
 begin
 begin
-  exit;
-
   StartLibrary(false);
   StartLibrary(false);
   Add([
   Add([
   'var Wing: word;',
   'var Wing: word;',
@@ -33855,6 +33854,11 @@ begin
   CheckResolverUnexpectedHints();
   CheckResolverUnexpectedHints();
 end;
 end;
 
 
+procedure TTestModule.TestLibrary_ExportUnitFunc;
+begin
+
+end;
+
 Initialization
 Initialization
   RegisterTests([TTestModule]);
   RegisterTests([TTestModule]);
 end.
 end.