mysticatea/regexpp

Missing support for js-supported character class

mattbishop opened this issue · 6 comments

I want to parse this regex:

/\p{ID_Start}\p{ID_Continue}+/u

Node 16 accepts it:

const idRegex = /^\p{ID_Start}\p{ID_Continue}+$/u
console.log(idRegex.test("anIdentifier")
// > true
console.log(idRegex.test("not an Identifier")
// > false

regexpp 3.2.0 does not:

regexpp.validateRegExpLiteral(/^\p{ID_Start}\p{ID_Continue}+$/u)
// > RangeError: Invalid code point -1
at Function.fromCodePoint in ECMAScript
at RegExpValidator.validateLiteral in regexpp/index.js  line 411
at Object.validateRegExpLiteral in regexpp/index.js  line 2084

These two character classes are important for programming language parsing: https://unicode.org/reports/tr31/

Hi @mattbishop .
validateRegExpLiteral accepts string.
I think may you need to do the following:

regexpp.validateRegExpLiteral(/^\p{ID_Start}\p{ID_Continue}+$/u.toString())

@mattbishop is this issue resolved?

@mattbishop I am able to confirm what ota-meshi said (that there is no bug). See: https://runkit.com/conartist6/624da94f206e790009a8a78b

As document here (and here), validateRegExpLiteral takes a string as its first argument, not a regex.

Ah I see now. I thought it could take a RegExp like parseRegExpLiteral. I will close this issue but it seems odd that parse takes both string and Regexp while validate only takes string.

Thanks for the clarification!