Skip to content

Commit 55ca331

Browse files
authored
Refactor to pass flag object to parsePattern() (#559)
1 parent 43f7ed0 commit 55ca331

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

lib/rules/require-unicode-regexp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function isSyntacticallyCompatible(pattern: Pattern): false | Pattern {
4646
pattern.raw,
4747
undefined,
4848
undefined,
49-
true,
49+
{ unicode: true },
5050
)
5151
} catch (_error) {
5252
return false

lib/rules/strict.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
defineRegexpVisitor,
1313
isEscapeSequence,
1414
} from "../utils"
15+
import type { ReadonlyFlags } from "regexp-ast-analysis"
1516

1617
const validator = new RegExpValidator({ strict: true, ecmaVersion: 2020 })
1718

@@ -21,10 +22,10 @@ const validator = new RegExpValidator({ strict: true, ecmaVersion: 2020 })
2122
*/
2223
function validateRegExpPattern(
2324
pattern: string,
24-
uFlag?: boolean,
25+
flags: ReadonlyFlags,
2526
): string | null {
2627
try {
27-
validator.validatePattern(pattern, undefined, undefined, uFlag)
28+
validator.validatePattern(pattern, undefined, undefined, flags)
2829
return null
2930
} catch (err) {
3031
return err instanceof Error ? err.message : null
@@ -272,10 +273,7 @@ export default createRule("strict", {
272273
// our own logic couldn't find any problems,
273274
// so let's use a real parser to do the job.
274275

275-
const message = validateRegExpPattern(
276-
pattern,
277-
flags.unicode,
278-
)
276+
const message = validateRegExpPattern(pattern, flags)
279277

280278
if (message) {
281279
context.report({

lib/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ function buildRegexpVisitor(
329329
patternSource.value,
330330
0,
331331
patternSource.value.length,
332-
flags.unicode,
332+
flags,
333333
)
334334
} catch (error: unknown) {
335335
if (error instanceof SyntaxError) {

lib/utils/regexp-ast/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export function getRegExpNodeFromExpression(
4242
node.regex.pattern,
4343
0,
4444
node.regex.pattern.length,
45-
node.regex.flags.includes("u"),
45+
{
46+
unicode: node.regex.flags.includes("u"),
47+
unicodeSets: node.regex.flags.includes("v"),
48+
},
4649
)
4750
} catch {
4851
return null

0 commit comments

Comments
 (0)