[Pas2js] "&" prefix support

warleyalex warleyalex at yahoo.com.br
Mon May 14 01:04:58 CEST 2018


Let's say we type the following piece
---------------
var 
  compressed_UInt8Array: TJSUint8Array;
begin
  (* when we type (dot) to invoke the code completion, you see a lot of
methods / properties
      uhh, there's a ugly underscore on the "_of" function, indeed it's an
external function. 
  *)
  compressed_UInt8Array := TJSUint8Array. 
---------------

Pas2JS can support for the "&" escape prefix to allow using reserved words
as identifiers.

If I prefix all "_" functions/methods in the JS.pas to "&" prefix, for
instance:
    function &then (onAccepted : TJSPromiseResolver) : TJSPromise; external
name 'then';
    function &finally(value : TJSPromiseFinallyHandler): TJSPromise;
    class function &of(aValue : jsValue) : TJSFloat32Array; varargs;

Did you realize that the code completion will show the reserved word as
expected, it will display 'of' instead of '_of', but we still have the ugly
'&of' in the source code, of course the compiler will emit 'of'.

  compressed_UInt8Array := TJSUint8Array.&of(1,2,3);

In the DWScript world, there's some magic, the compiler escape the "&"
prefix to allow using reserved words as identifiers! So, the compiler
understands something like this:

  compressed_UInt8Array := TJSUint8Array.of(1,2,3);

  or

  defer
    .then(doTask1)
    .then(doTask2);






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


More information about the Pas2js mailing list