13
13
*
14
14
* @callback TestFunctionAnything
15
15
* @param {Node } node
16
- * @param {number } [index]
17
- * @param {Parent } [parent]
16
+ * @param {number|null|undefined } [index]
17
+ * @param {Parent|null|undefined } [parent]
18
18
* @returns {boolean|void }
19
19
*/
20
20
24
24
* @template {Node} X
25
25
* @callback TestFunctionPredicate
26
26
* @param {Node } node
27
- * @param {number } [index]
28
- * @param {Parent } [parent]
27
+ * @param {number|null|undefined } [index]
28
+ * @param {Parent|null|undefined } [parent]
29
29
* @returns {node is X }
30
30
*/
31
31
32
32
/**
33
33
* @callback AssertAnything
34
34
* @param {unknown } [node]
35
- * @param {number } [index]
36
- * @param {Parent } [parent]
35
+ * @param {number|null|undefined } [index]
36
+ * @param {Parent|null|undefined } [parent]
37
37
* @returns {boolean }
38
38
*/
39
39
43
43
* @template {Node} Y
44
44
* @callback AssertPredicate
45
45
* @param {unknown } [node]
46
- * @param {number } [index]
47
- * @param {Parent } [parent]
46
+ * @param {number|null|undefined } [index]
47
+ * @param {Parent|null|undefined } [parent]
48
48
* @returns {node is Y }
49
49
*/
50
50
@@ -54,8 +54,8 @@ export const is =
54
54
* When a `parent` node is known the `index` of node should also be given.
55
55
*
56
56
* @type {(
57
- * (<T extends Node>(node: unknown, test: T['type']|Partial<T>|TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|TestFunctionPredicate<T>>, index?: number, parent?: Parent, context?: unknown) => node is T) &
58
- * ((node?: unknown, test?: Test, index?: number, parent?: Parent, context?: unknown) => boolean)
57
+ * (<T extends Node>(node: unknown, test: T['type']|Partial<T>|TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|TestFunctionPredicate<T>>, index?: number|null|undefined , parent?: Parent|null|undefined , context?: unknown) => node is T) &
58
+ * ((node?: unknown, test?: Test, index?: number|null|undefined , parent?: Parent|null|undefined , context?: unknown) => boolean)
59
59
* )}
60
60
*/
61
61
(
@@ -70,8 +70,8 @@ export const is =
70
70
* When `function` checks if function passed the node is true.
71
71
* When `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
72
72
* When `array`, checks any one of the subtests pass.
73
- * @param {number } [index] Position of `node` in `parent`
74
- * @param {Parent } [parent] Parent of `node`
73
+ * @param {number|null|undefined } [index] Position of `node` in `parent`
74
+ * @param {Parent|null|undefined } [parent] Parent of `node`
75
75
* @param {unknown } [context] Context object to invoke `test` with
76
76
* @returns {boolean } Whether test passed and `node` is a `Node` (object with `type` set to non-empty `string`).
77
77
*/
@@ -104,7 +104,7 @@ export const is =
104
104
throw new Error ( 'Expected both parent and index' )
105
105
}
106
106
107
- // @ts -ignore Looks like a node.
107
+ // @ts -expect-error Looks like a node.
108
108
return node && node . type && typeof node . type === 'string'
109
109
? Boolean ( check . call ( context , node , index , parent ) )
110
110
: false
@@ -175,6 +175,8 @@ function anyFactory(tests) {
175
175
while ( ++ index < checks . length ) {
176
176
if ( checks [ index ] . call ( this , ...parameters ) ) return true
177
177
}
178
+
179
+ return false
178
180
}
179
181
}
180
182
@@ -197,7 +199,8 @@ function propsFactory(check) {
197
199
let key
198
200
199
201
for ( key in check ) {
200
- if ( node [ key ] !== check [ key ] ) return
202
+ // @ts -expect-error: hush, it sure works as an index.
203
+ if ( node [ key ] !== check [ key ] ) return false
201
204
}
202
205
203
206
return true
@@ -237,6 +240,7 @@ function castFactory(check) {
237
240
* @returns {boolean }
238
241
*/
239
242
function assertion ( ...parameters ) {
243
+ // @ts -expect-error: spreading is fine.
240
244
return Boolean ( check . call ( this , ...parameters ) )
241
245
}
242
246
}
0 commit comments