[Pas2js] ISSUE: Pas2JS wrongly/silently 'cares' about the number of spaces within a `$define` compiler directive

Frameworks developer.frameworks at gmail.com
Wed Aug 15 01:25:30 CEST 2018


Hello Pas2JS and TMS Teams -

The following cruelty was discovered during a protracted TDD session and
after a bout of OCD in which I simply had to right-justify all my [nested]
compile-time directives. This problem was first observed using Pas2JS
Compiler version 1.0.0rc1 [2018/07/25] for Win32 i386 when developing with
TMS WEB Core version v1.0.0.3 on RAD Studio/Delphi Enterprise v10.2.3.

Viewing the Pas2js_Issue_20180814.lpr unit below (and a screen grab of its
resulting output in the browser's console), note that Pas2js wrongly and,
worse yet, silently "cares" about the number of spaces within a compiler
directive (one space is good; two or more are bad). With [THAT] said, I
think [THIS] should be fixed as all directives, except switch directives,
must have at least one space (*but may have more*) between the directive
name and its parameter(s). This was otherwise a tricky bug to quash being
non-obvious as well as nonsensical.

Regards,

J Ralston
Frameworks
Pas2js_Issue_20180814.lpr (source file attached)

program Pas2js_Issue_20180814;

uses WEB;

begin
  {$define  THIS}{<-- apparently Pas2js cares about the extra space before THIS}
   {$define THAT}

  {$ifdef THIS}
    console.log( 'Strangely, THIS will NOT print with the following
statement.' );
    console.log( 'Per Object Pascal conventions, all directives, except switch '
               + 'directives, must have at least one space (but may have more) '
               + 'between the directive name and its parameter(s).' );
  {$endif}
  {$ifdef  THIS}{<-- yet, correctly, Pas2js doesn't care about it here}
    console.log( 'Also, THIS will NOT print.' );
  {$endif}
  {$if defined( THIS) or defined(THIS)}{<-- nor here}
    console.log( 'Neither will THIS print either.' );
  {$endif}

  {$ifdef THAT}
    console.log( 'Per Object Pascal conventions, all directives, except switch '
               + 'directives, must have at least one space (but may have more) '
               + 'between the directive name and its parameter(s).' );
    console.log( 'With THAT understood, the above did print.' );
  {$endif}
  {$if defined( THAT) and defined(THAT)}{<-- nor here}
    console.log( 'Like a day, what a difference a single space can make!' );
    console.log( 'Now I wonder how many such directives are being
ignored globally?' );
  {$endif}
end.

Pas2js_Issue_20180814.html (browser launch file)

<html>
  <head>
    <meta charset="utf-8"/>
    <title>Pas2js Issue 20180814</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="Pas2JS Issue Report"/>
    <meta name="keywords" content="Issues,Pas2JS,Pascal,JavaScript"/>
    <meta name="author" content="J Ralston"/>
    <meta name="company" content="Frameworks"/>
    <script type="application/javascript"
src="Pas2js_Issue_20180814.js"></script>
  </head>
  <body>
    <script type="application/javascript">
     rtl.run();
    </script>
  </body>
</html>

Browser's Console Output


(Related JavaScript produced with Pas2JS Compiler version 1.0.0
[2018/08/09] for Win32 i386)


This issue has been further investigated and reproduced directly using the
Pas2JS Compiler version 1.0.0 [2018/08/09] for Win32 i386 (with neither
Delphi nor TMS WEB Core present).

Separately of note here due to a shared compiler code base, this issue has
not been investigated on FPC but perhaps should be.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20180814/f246b7f8/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 24081 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20180814/f246b7f8/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Pas2js_Issue_20180814.lpr
Type: application/octet-stream
Size: 1338 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20180814/f246b7f8/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2018-08-14_17-41-54.png
Type: image/png
Size: 34472 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20180814/f246b7f8/attachment-0003.png>


More information about the Pas2js mailing list