Escaping JavaScript variables does not work properly

Issue #103 resolved
Christian Budde created an issue

In order to set the resource strings from within a (JSCodeGen'ed) project it's necessary to update the $R variable.

However, it's currently not possible to do so (at least I do not know any working ways). If for example one would write something like:

asm
   $R = ["some content"]
end;

the compiler complains "Hexadecimal digit expected".

To make it compile it's necessary to escape the $ sign like:

asm
   &$R = ["some content"]
end;

However, this unfortunately ends in code still containing the escape character "&".

Comments (4)

  1. Christian Budde reporter

    I just found a good workaround for this issue:

    var ResourceStrings external '$R': Variant;
    

    It doesn't render the issue invalid, but at least it's working and it's more pascalish.

  2. Eric Grange repo owner

    Issues traces to TdwsJSLanguageExtension.ReadInstr, which does a TestName before switching the tokenizer, and if the first token within the asm block is a name starting with '$' it goes kaboom.

    asm
       ; $R = ["some content"]
    end;
    

    And yes, using an external variant is preferable, you can also use an external function (tagged with "property") if you want it to be read-only:

    function ResourceStrings : Variant; external '$R' property;
    

    (it's the syntax for JS external properties, but it works in that case as well)

  3. Log in to comment