Javascript lexer overzealous about highlighting regexps

Issue #356 resolved
created an issue

Here are two examples.

{{{ var x = 1/(1+Math.sqrt(sum)) // convert to number between 1-0 return Math.round((num / den) * 100)/100 }}}

Comments (5)

  1. thatch reporter

    I propose a quick heuristic:

    • `/` followed by `[gsmi]
      b` is a regex with suffix
    • `/` followed by `
      s*[,);]` is the end of a regex.
    • `/` followed by `
      .[a-z]` is the end of a regex with part of a method call.
    • `/` followed by `
      s*[0-9(]` is definitely not the end of a regex.

    These would stay regexes:

    x = /abc/;
    x = /abc/.match;

    These specific misparses would be fixed:

    blah(1/2); //comment
    x = 1 / 2 / 3;
    x = 1/1/.1;

    These would still be broken:

        (treats =/ as an operator, while x is a regex in Firefox 3)
        (the g looks like a modifier, but this correctly is treated as math by Firefox 3)
        (same as above)

    The last two also are mishandled in vim. Without variable length lookbehind I don't see an easy way to fix these. See [febbbf8f29c2] for the fix, which I think is good enough to close this ticket.

  2. Log in to comment