[Pas2js] The goal of pas2js

warleyalex warleyalex at yahoo.com.br
Sun Dec 30 17:13:06 CET 2018


Michael said: "I wish to repeat that the goal of pas2js is to make pascal
available in the browser. 
The goal is not to make pascal resemble Javascript." 

However, I wish the general purpose and were not limited to pascal available
in the browser.
Pas2js should be an full extented feature language; the language can support
several syntax and features/extensions introduced similar to Delphi Prism /
Oxygene / DWScript / FPC, as well as various language extensions, "make
pascal resemble Javascript".

a) variables can be declared in-line anywhere in the code, allowing code
like
for var i:=1 to 10 do begin
   var k : Integer;
   (...)
end;

b) variables can be initialized to custom values upon declaration
var obj : TMyObject = TMyObject.Create;

c) if then else alternative feature 
var
  msg: String;
begin
  msg := "There are " + IntToStr(n) + " user" + if (n>1) then "s" else "";
end;

d) has support the operator ?? 
var 
  x: JSValue; 
begin 
  console.log(x ?? 1);  // it translates to something like x || 1
end; 

e) anonymous classes syntax, to emit literal objects:

type 
  THandleArray = array of JSValue; 

function list: THandleArray; 
begin 
result := [ 
  CLASS 
    l   := 'fieldA1'; external name 'length'; 
    w := 'fieldB1'; external name 'width'; 
  END, 
  CLASS 
    l   := 'fieldA2'; external name 'length'; 
    w := 'fieldB2'; external name 'width'; 
  END, 
  CLASS 
    l  := 'fieldA3'; external name 'length'; 
    w := 'fieldB3'; external name 'width'; 
  END]; 

end; 

to emit literal objects

function list() { 
   var Result = []; 
   Result = [{ 
      "width" : "fieldB1" 
      ,"length" : "fieldA1" 
   }, { 
      "width" : "fieldB2" 
      ,"length" : "fieldA2" 
   }, { 
      "width" : "fieldB3" 
      ,"length" : "fieldA3" 
   }].slice(); 
   return Result 
}; 

f) nested records syntax:

  TTestCustomJSONArraySimpleArray = record
    F: String;
    G: array of String;
    H: record
      H1: Integer;
      H2: String;
      H3: record
        H3a: Boolean;
        H3b: TSQLRawBlob;
      end;
    end;
    I: TDateTime;
    J: array of record
      J1: Byte;
      J2: TGUID;
      J3: TRecordEnum;
    end;
  end;

f) Partial classes
TWebCustomControl = partial class(TWebMovableControl)

g) type helpers
   TIntegerHelper = helper for Integer
      function ToString2 : String;
   end;





--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list