@@ -73,6 +73,39 @@ function collectIntersectionOperands(
73
73
return operands
74
74
}
75
75
76
+ /** Gets the parsed result element. */
77
+ function getParsedElement (
78
+ pattern : string ,
79
+ flags : ReadonlyFlags ,
80
+ ) : ToUnicodeSetElement | null {
81
+ try {
82
+ const ast = new RegExpParser ( ) . parsePattern (
83
+ pattern ,
84
+ undefined ,
85
+ undefined ,
86
+ {
87
+ unicode : flags . unicode ,
88
+ unicodeSets : flags . unicodeSets ,
89
+ } ,
90
+ )
91
+ if ( ast . alternatives . length === 1 )
92
+ if ( ast . alternatives [ 0 ] . elements . length === 1 ) {
93
+ const element = ast . alternatives [ 0 ] . elements [ 0 ]
94
+ if (
95
+ element . type !== "Assertion" &&
96
+ element . type !== "Quantifier" &&
97
+ element . type !== "CapturingGroup" &&
98
+ element . type !== "Group" &&
99
+ element . type !== "Backreference"
100
+ )
101
+ return element
102
+ }
103
+ } catch ( _error ) {
104
+ // ignore
105
+ }
106
+ return null
107
+ }
108
+
76
109
export default createRule ( "simplify-set-operations" , {
77
110
meta : {
78
111
docs : {
@@ -384,36 +417,3 @@ export default createRule("simplify-set-operations", {
384
417
} )
385
418
} ,
386
419
} )
387
-
388
- /** Gets the parsed result element. */
389
- function getParsedElement (
390
- pattern : string ,
391
- flags : ReadonlyFlags ,
392
- ) : ToUnicodeSetElement | null {
393
- try {
394
- const ast = new RegExpParser ( ) . parsePattern (
395
- pattern ,
396
- undefined ,
397
- undefined ,
398
- {
399
- unicode : flags . unicode ,
400
- unicodeSets : flags . unicodeSets ,
401
- } ,
402
- )
403
- if ( ast . alternatives . length === 1 )
404
- if ( ast . alternatives [ 0 ] . elements . length === 1 ) {
405
- const element = ast . alternatives [ 0 ] . elements [ 0 ]
406
- if (
407
- element . type !== "Assertion" &&
408
- element . type !== "Quantifier" &&
409
- element . type !== "CapturingGroup" &&
410
- element . type !== "Group" &&
411
- element . type !== "Backreference"
412
- )
413
- return element
414
- }
415
- } catch ( _error ) {
416
- // ignore
417
- }
418
- return null
419
- }
0 commit comments