Skip to content

Commit d15b837

Browse files
committed
fix: improve InclusiveDescendant performance
1 parent b4e685d commit d15b837

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/complex-types.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/ban-types */
22

33
import type {Node, Parent} from 'unist'
4+
import type {LessThan, Subtract} from 'type-fest'
45
import type {Test} from 'unist-util-is'
56
import type {Visitor} from './index.js'
67

@@ -9,13 +10,17 @@ import type {Visitor} from './index.js'
910
*/
1011
export type InclusiveDescendant<
1112
Tree extends Node = never,
12-
Found = void
13-
> = Tree extends Parent
13+
Found = void,
14+
Depth extends number = 5
15+
> = LessThan<Depth, 0> extends true
16+
? Tree
17+
: Tree extends Parent
1418
?
1519
| Tree
1620
| InclusiveDescendant<
1721
Exclude<Tree['children'][number], Found | Tree>,
18-
Found | Tree
22+
Found | Tree,
23+
Subtract<Depth, 1>
1924
>
2025
: Tree
2126

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@
6161
"strip-ansi": "^7.0.0",
6262
"tsd": "^0.25.0",
6363
"type-coverage": "^2.0.0",
64+
"type-fest": "^4.32.0",
6465
"typescript": "^4.7.0",
65-
"xo": "^0.53.0"
66+
"xo": "^0.60.0"
6667
},
6768
"scripts": {
6869
"prepack": "npm run build && npm run format",

0 commit comments

Comments
 (0)