Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having "-" as literall match thingies causes invalid escape sequences to be generated when using the unicode #144

Open
TheGrandmother opened this issue Jul 23, 2020 · 4 comments

Comments

@TheGrandmother
Copy link

TheGrandmother commented Jul 23, 2020

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

@tjvr
Copy link
Collaborator

tjvr commented Jul 31, 2020

Ooh, that's surprising!

@tjvr tjvr added the bug label Jul 31, 2020
@nathan
Copy link
Collaborator

nathan commented Aug 10, 2020

@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).

@tjvr
Copy link
Collaborator

tjvr commented Aug 13, 2020

If someone wants to raise a PR which updates reEscape (or whatever the function’s called), that would be great.

@fabiosantoscode
Copy link

I've worked around this by simply changing '-' to /-/u, putting this out here in case it's helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants