moo
moo copied to clipboard
Having "-" as literall match thingies causes invalid escape sequences to be generated when using the unicode
If i have the following token defined:
ARITHMETIC: ['+' , '-'],
And all my regular expressions are using the u
flag moo
will output an an invalid regex escape sequence as \-
is apparently uncool when rolling with the u
flag.
Changing the token definition to:
ARITHMETIC: ['+' , /-/u],
works but is not pretty.
moo version 0.5.1 Node version 13.14.0
Ooh, that's surprising!
@tjvr simplest fix is to escape -
as \x2d
(which works everywhere) instead of \-
(which only works inside []
in Unicode mode, even under Annex B).
It's incomprehensible why TC39 decided to make the RegExp grammar this inconsistently nitpicky (e.g., \{
works fine inside a Unicode character class even though the backslash does nothing).
If someone wants to raise a PR which updates reEscape
(or whatever the function’s called), that would be great.
I've worked around this by simply changing '-'
to /-/u
, putting this out here in case it's helpful.