2 * @fileoverview Common utils for regular expressions.
3 * @author Josh Goldberg
4 * @author Toru Nagashima
9 const { RegExpValidator
} = require("@eslint-community/regexpp");
11 const REGEXPP_LATEST_ECMA_VERSION
= 2022;
14 * Checks if the given regular expression pattern would be valid with the `u` flag.
15 * @param {number} ecmaVersion ECMAScript version to parse in.
16 * @param {string} pattern The regular expression pattern to verify.
17 * @returns {boolean} `true` if the pattern would be valid with the `u` flag.
18 * `false` if the pattern would be invalid with the `u` flag or the configured
19 * ecmaVersion doesn't support the `u` flag.
21 function isValidWithUnicodeFlag(ecmaVersion
, pattern
) {
22 if (ecmaVersion
<= 5) { // ecmaVersion <= 5 doesn't support the 'u' flag
26 const validator
= new RegExpValidator({
27 ecmaVersion
: Math
.min(ecmaVersion
, REGEXPP_LATEST_ECMA_VERSION
)
31 validator
.validatePattern(pattern
, void 0, void 0, /* uFlag = */ true);
40 isValidWithUnicodeFlag
,
41 REGEXPP_LATEST_ECMA_VERSION