@@ -8,7 +8,7 @@ import type { Rule, AST, SourceCode } from "eslint"
8
8
import { getStringIfConstant } from "./ast-utils"
9
9
import type { ReadonlyFlags , ToCharSetElement } from "regexp-ast-analysis"
10
10
// eslint-disable-next-line no-restricted-imports -- Implement RegExpContext#toCharSet
11
- import { toCharSet } from "regexp-ast-analysis"
11
+ import { toCharSet , toCache } from "regexp-ast-analysis"
12
12
import type { CharSet } from "refa"
13
13
import { JS } from "refa"
14
14
import type { UsageOfPattern } from "./get-usage-of-pattern"
@@ -89,7 +89,7 @@ type RegExpContextBase = {
89
89
patternAst : Pattern
90
90
patternSource : PatternSource
91
91
92
- flags : ReadonlyFlags
92
+ flags : Required < ReadonlyFlags >
93
93
}
94
94
export type RegExpContextForLiteral = {
95
95
node : ESTree . RegExpLiteral
@@ -109,7 +109,7 @@ type UnparsableRegExpContextBase = {
109
109
node : ESTree . Expression
110
110
regexpNode : ESTree . RegExpLiteral | ESTree . CallExpression
111
111
112
- flags : ReadonlyFlags
112
+ flags : Required < ReadonlyFlags >
113
113
flagsString : string | null
114
114
ownsFlags : boolean
115
115
@@ -578,7 +578,7 @@ function buildRegExpContextBase({
578
578
regexpNode,
579
579
flagsNode,
580
580
context,
581
- flags,
581
+ flags : originalFlags ,
582
582
parsedPattern,
583
583
} : {
584
584
patternSource : PatternSource
@@ -589,8 +589,8 @@ function buildRegExpContextBase({
589
589
parsedPattern : Pattern
590
590
} ) : RegExpContextBase {
591
591
const sourceCode = context . getSourceCode ( )
592
+ const flags = toCache ( originalFlags )
592
593
593
- const cacheCharSet = new WeakMap < ToCharSetElement , CharSet > ( )
594
594
let cacheUsageOfPattern : UsageOfPattern | null = null
595
595
return {
596
596
toCharSet : ( node , optionFlags ) => {
@@ -599,13 +599,7 @@ function buildRegExpContextBase({
599
599
return toCharSet ( node , optionFlags )
600
600
}
601
601
602
- let charSet = cacheCharSet . get ( node )
603
- if ( charSet ) {
604
- return charSet
605
- }
606
- charSet = toCharSet ( node , flags )
607
- cacheCharSet . set ( node , charSet )
608
- return charSet
602
+ return toCharSet ( node , flags )
609
603
} ,
610
604
getRegexpLocation : ( range , offsets ) => {
611
605
if ( offsets ) {
@@ -652,7 +646,7 @@ function buildUnparsableRegExpContextBase({
652
646
patternNode,
653
647
regexpNode,
654
648
context,
655
- flags,
649
+ flags : originalFlags ,
656
650
flagsString,
657
651
flagsNode,
658
652
ownsFlags,
@@ -667,6 +661,7 @@ function buildUnparsableRegExpContextBase({
667
661
ownsFlags : boolean
668
662
} ) : UnparsableRegExpContextBase {
669
663
const sourceCode = context . getSourceCode ( )
664
+ const flags = toCache ( originalFlags )
670
665
671
666
return {
672
667
regexpNode,
0 commit comments