1
1
import type { Rule } from "eslint"
2
- import type { ClosestAncestor } from "regexp-ast-analysis"
3
2
import { getClosestAncestor } from "regexp-ast-analysis"
4
- import type { Node , Quantifier } from "@eslint-community/regexpp/ast"
3
+ import type { Quantifier } from "@eslint-community/regexpp/ast"
5
4
import type { RegExpContext } from "."
6
5
import { quantToString } from "."
7
6
import type { CanSimplify } from "./regexp-ast/simplify-quantifier"
@@ -14,10 +13,7 @@ export function fixSimplifyQuantifier(
14
13
result : CanSimplify ,
15
14
{ fixReplaceNode } : RegExpContext ,
16
15
) : [ replacement : string , fix : ( fixer : Rule . RuleFixer ) => Rule . Fix | null ] {
17
- const ancestor = getClosestAncestorOfAll ( [
18
- quantifier ,
19
- ...result . dependencies ,
20
- ] )
16
+ const ancestor = getClosestAncestor ( quantifier , ...result . dependencies )
21
17
22
18
let replacement : string
23
19
if ( quantifier . min === 0 ) {
@@ -45,18 +41,3 @@ export function fixSimplifyQuantifier(
45
41
} ) ,
46
42
]
47
43
}
48
-
49
- /**
50
- * Returns the closest ancestor of all given elements.
51
- */
52
- function getClosestAncestorOfAll < T extends Node > (
53
- elements : readonly [ T , ...T [ ] ] ,
54
- ) : ClosestAncestor < T , T > {
55
- let leftMost = elements [ 0 ]
56
- let rightMost = elements [ 0 ]
57
- for ( const e of elements ) {
58
- if ( e . start < leftMost . start ) leftMost = e
59
- if ( e . end > rightMost . end ) rightMost = e
60
- }
61
- return getClosestAncestor ( leftMost , rightMost )
62
- }
0 commit comments