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

Michael Van Canneyt michael at freepascal.org
Wed Aug 15 10:19:54 CEST 2018


Hello,

Thanks for the bugreport.

Fixed in trunk.

By the way, you can perfectly use writeln() instead of console.log().

If you then include the browserconsole unit, the output will be displayed in the
console, but also on a terminal-like display in the browser itself. You can
even set the number of lines. You can even style the console, if you are so
inclined.

Michael.

PS. 
The Pas2js Support <support at pas2js.org> address does not exist.
pas2js.org is not registered by us.

On Tue, 14 Aug 2018, Frameworks wrote:

> 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.
>


More information about the Pas2js mailing list