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

Fix parseFlags #571

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-rules-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-regexp": patch
---

Fix `parseFlags`
10 changes: 7 additions & 3 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ type RegexpRule = ParsableRegexpRule & UnparsableRegexpRule
const regexpRules = new WeakMap<ESTree.Program, RegexpRule[]>()

export const FLAG_GLOBAL = "g"
export const FLAG_DOTALL = "s"
export const FLAG_DOT_ALL = "s"
export const FLAG_HAS_INDICES = "d"
export const FLAG_IGNORECASE = "i"
export const FLAG_MULTILINE = "m"
export const FLAG_STICKY = "y"
export const FLAG_UNICODE = "u"
export const FLAG_UNICODE_SETS = "v"

const flagsCache = new Map<string, ReadonlyFlags>()
const flagsCache = new Map<string, Required<ReadonlyFlags>>()

/**
* Given some flags, this will return a parsed flags object.
Expand All @@ -196,12 +198,14 @@ export function parseFlags(flags: string): ReadonlyFlags {
let cached = flagsCache.get(flags)
if (cached === undefined) {
cached = {
dotAll: flags.includes(FLAG_DOTALL),
dotAll: flags.includes(FLAG_DOT_ALL),
global: flags.includes(FLAG_GLOBAL),
hasIndices: flags.includes(FLAG_HAS_INDICES),
ignoreCase: flags.includes(FLAG_IGNORECASE),
multiline: flags.includes(FLAG_MULTILINE),
sticky: flags.includes(FLAG_STICKY),
unicode: flags.includes(FLAG_UNICODE),
unicodeSets: flags.includes(FLAG_UNICODE_SETS),
}
flagsCache.set(flags, cached)
}
Expand Down