Special unicode characters crash the browser/javascript

When the TMS Web Core program code contains some very special unicode characters (codepoints), the compiled (transpiled) js program no longer runs correctly in the browser.

A minimalistic web app, that only has one button, demonstrates this:

26 procedure TForm14.WebButton1Click(Sender: TObject);
27 Const S = #$2028 + ' this crashes';
28 begin
29  if S<>'' then
30   Console.log('foo')
31 end;

In this example, the unicode character represented by #$2028 is causing the problem. #$2028 is the code for "line separator (unicode)".

Compiling this does not show any problems. Launching the app in any browser seems OK either. Clicking the button writes "foo" into the console, as expected.

BUT: To the right, the console should show "Unit14.pas:30". Instead, what it shows is "Unit14.pas:26", or any other arbitrary line number. Also, when setting a break point, e.g. at line 29, the browser never stops there.

Here is how it looks on my system:

In more complex programs, the effects may be even more subtle. Finding the root cause for such an erronous behaviour can be very challenging!

How to fix?

Changing the code like this seems to fix the problem:

Const
 C = Chr($2028);
 S = C + ' this does not crash';
begin
 if S<>'' then
  Console.log('foo')
end;

Make sure to not mixup Chr() and Char(). Using Char($2028) would compile, but the problem would persist.

Maybe TMS can ask the PAS2JS team for a list of such "dangerous" characters or even better, have the compiler complain about these.

Thanks for reporting.
We'll check with the pas2js team.

This problem was reported and fixed. We have a transpiler update that fixes this.