JS highlighting gets confused by template strings containing an apostrophe

JS highlighting gets confused by template strings containing an apostrophe


    22:20 - 21 days ago#1

    It seems that JavaScript syntax highlighting in UltraEdit does not disregard apostrophes in template strings defined with ` (grave accent). 
    In the example (attachment), the code under string_a is highlighted properly. The code highlighting under string_b is confused as it seems to be waiting for a second apostrophe to indicate a string completion.

    Code: Select all

    let string_a = `a simple string`;
    let string_b = `a simple ' string`;
    javascript_string_highlighting.png (120.71KiB)
    JavaScript string highlighting with ' in a string defined with `

    Grand MasterGrand Master

      7:06 - 20 days ago#2

      The syntax highlighting wordfile javascript.uew as installed with UltraEdit for Windows v2023.2.0.27 has as first line:

      Code: Select all

      /L9"JavaScript" JSCRIPT_LANG Line Comment = // Block Comment On = /* Block Comment Off = */ Escape Char = \ String Chars = '" File Extensions = JS TS
      There are defined only ' (apostrophe) and " (quotation mark) as characters marking beginning/end of a string with \ (backslash) as escape character inside a string. There is neither the keyword EnableMLS nor DisableMLS in the first line of the wordfile for JavaScript syntax highlighting which means an implicit usage of EnableMLS resulting in enabling multi-line string highlighting. A user can add the keyword DisableMLS left to File Extensions = to disable multi-line string highlighting which would at least result in stopping the wrong highlighting at the end of the line containing such a string.

      There cannot be defined more than two string characters according to the description on the syntax highlighting help page. I tried nevertheless String Chars = '"` but strings defined with ` are not highlighted at all by UltraEdit for Windows v2023.2.0.27.

      It should be possible to add to the wordfile:

      Code: Select all

      /Marker Characters = "``"
      /C9"Template literals"
      The delimiters line needs to be additionally changed from

      Code: Select all

      /Delimiters = ! " %&'()*+,-./:;<=>?@[\]^`{|}~

      Code: Select all

      /Delimiters = ! " %&'()*+,-./:;<=>?@[\]^{|}~
      Note: The character between " and % is a horizontal tab character and not a normal space as displayed by the web browser.

      But the highlighting of strings according to a marker characters definition with identical character for beginning/end of the marked string is unfortunately not working anymore since v23.10.0.1 in UltraEdit for Windows. (UE for Windows v2023.2.0.27 is v30.2.0.27 in former versioning scheme as used for UltraEdit for Windows before the year 2022). I reported this issue by email to UltraEdit support but it is still not fixed in current version 2023.2.0.27 of UltraEdit for Windows. There is working currently with UltraEdit for Windows only strings marked with different characters for beginning and end like [].

      I don't have a MAC. I don't use for that reason UltraEdit for MAC. I don't know the syntax highlighting wordfile for JavaScript installed with UltraEdit for MAC and you did not post the wordfile used by you which somehow highlights strings within grave accents (backticks) not syntax highlighted at all by UltraEdit for Windows.

      A simple solution is ignoring the fact that simple strings can be defined in JavaScript/ECMAScript since ECMAScript® 2015 also with a grave accent (backtick) at the beginning and the end and use only ' and " for simple strings in JavaScript files which increases also the compatibility with older web browsers not supporting template literals at all. The usage of template strings makes of course the string concatenation with values of variables easier for script writers which was the reason for introducing them to JavaScript/ECMAScript. Please report this syntax highlighting issue of UltraEdit for MAC with strings defined with grave accents containing an apostrophe or a quotation mark by email to UltraEdit support If that is unacceptable for you for whatever reason. Please see the technical support page for information on how to report an issue.

      I doubt that UltraEdit will support real template literals syntax highlighting in future as that would require real JavaScript/ECMAScript language intellisense for recognizing which part of a template literal is a string and which part is an expression which should be syntax highlighted as defined in the wordfile for character streams outside of a normal string, comment, or marked string. However, if there are enough UltraEdit users requesting real syntax highlighting support for template literals in JavaScript/ECMAScript files, I am quite sure that UltraEdit, Inc. will enhance UltraEdit for real syntax highlighting of template literals.
      Best regards from an UC/UE/UES for Windows user from Austria