Skip to content

Commit efca081

Browse files
committed
move getParsedElement
1 parent 9dea8e6 commit efca081

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

lib/rules/simplify-set-operations.ts

+33-33
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,39 @@ function collectIntersectionOperands(
7373
return operands
7474
}
7575

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+
76109
export default createRule("simplify-set-operations", {
77110
meta: {
78111
docs: {
@@ -384,36 +417,3 @@ export default createRule("simplify-set-operations", {
384417
})
385418
},
386419
})
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

Comments
 (0)