syntax-tree / unist-util-is

Compare fc608c6 ... +3 ... f7c1d67

Coverage Reach
index.js

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 7 files from the diff.
Other files ignored by Codecov
package.json has changed.
index.test-d.ts has changed.
test/main.js has changed.
tsconfig.json has changed.
test/property.js has changed.
readme.md has changed.

@@ -13,8 +13,8 @@
Loading
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,16 +24,16 @@
Loading
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,19 +43,19 @@
Loading
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
51 -
export var is =
51 +
export const is =
52 52
  /**
53 53
   * Check if a node passes a test.
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,14 +70,14 @@
Loading
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
     */
78 78
    // eslint-disable-next-line max-params
79 79
    function is(node, test, index, parent, context) {
80 -
      var check = convert(test)
80 +
      const check = convert(test)
81 81
82 82
      if (
83 83
        index !== undefined &&
@@ -104,14 +104,14 @@
Loading
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
111 111
    }
112 112
  )
113 113
114 -
export var convert =
114 +
export const convert =
115 115
  /**
116 116
   * @type {(
117 117
   *   (<T extends Node>(test: T['type']|Partial<T>|TestFunctionPredicate<T>) => AssertPredicate<T>) &
@@ -139,8 +139,7 @@
Loading
139 139
      }
140 140
141 141
      if (typeof test === 'object') {
142 -
        // @ts-ignore looks like a list of tests / partial test object.
143 -
        return 'length' in test ? anyFactory(test) : propsFactory(test)
142 +
        return Array.isArray(test) ? anyFactory(test) : propsFactory(test)
144 143
      }
145 144
146 145
      if (typeof test === 'function') {
@@ -156,8 +155,8 @@
Loading
156 155
 */
157 156
function anyFactory(tests) {
158 157
  /** @type {Array.<AssertAnything>} */
159 -
  var checks = []
160 -
  var index = -1
158 +
  const checks = []
159 +
  let index = -1
161 160
162 161
  while (++index < tests.length) {
163 162
    checks[index] = convert(tests[index])
@@ -171,11 +170,13 @@
Loading
171 170
   * @returns {boolean}
172 171
   */
173 172
  function any(...parameters) {
174 -
    var index = -1
173 +
    let index = -1
175 174
176 175
    while (++index < checks.length) {
177 176
      if (checks[index].call(this, ...parameters)) return true
178 177
    }
178 +
179 +
    return false
179 180
  }
180 181
}
181 182
@@ -195,10 +196,11 @@
Loading
195 196
   */
196 197
  function all(node) {
197 198
    /** @type {string} */
198 -
    var key
199 +
    let key
199 200
200 201
    for (key in check) {
201 -
      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
202 204
    }
203 205
204 206
    return true
@@ -238,6 +240,7 @@
Loading
238 240
   * @returns {boolean}
239 241
   */
240 242
  function assertion(...parameters) {
243 +
    // @ts-expect-error: spreading is fine.
241 244
    return Boolean(check.call(this, ...parameters))
242 245
  }
243 246
}

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
index.js 100.00%
Project Totals (1 files) 100.00%
Loading