Skip to content

Commit

Permalink
Fix parseFlags (#571)
Browse files Browse the repository at this point in the history
* Fix `parseFlags`

* Create wicked-rules-rhyme.md
  • Loading branch information
RunDevelopment committed Sep 8, 2023
1 parent ac381bc commit 36b8e73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 36b8e73

Please sign in to comment.