11/**
2- * @typedef {import('unist-util-assert').AssertionError } AssertionError
2+ * @typedef {import('hast').Literals } Literals
3+ * @typedef {import('hast').Element } Element
4+ * @typedef {import('hast').Nodes } Nodes
5+ * @typedef {import('hast').Parents } Parents
6+ * @typedef {import('hast').Root } Root
37 *
48 * @typedef {import('unist').Node } UnistNode
59 * @typedef {import('unist').Parent } UnistParent
6- * @typedef {import('unist').Literal } UnistLiteral
7- * @typedef {import('hast').Root } Root
8- * @typedef {import('hast').Content } Content
9- * @typedef {import('hast').Element } Element
10- */
11-
12- /**
13- * @typedef {Root | Content } Node
14- * @typedef {Extract<Node, UnistParent> } Parent
15- * @typedef {Extract<Node, UnistLiteral> } Literal
10+ *
11+ * @typedef {import('unist-util-assert').AssertionError } AssertionError
1612 */
1713
1814import nodeAssert from 'node:assert'
19- import { zwitch } from 'zwitch'
2015import { mapz } from 'mapz'
2116import {
17+ _void ,
2218 assert as unistAssert ,
23- parent as unistParent ,
2419 literal as unistLiteral ,
25- wrap ,
26- _void
20+ parent as unistParent ,
21+ wrap
2722} from 'unist-util-assert'
23+ import { zwitch } from 'zwitch'
2824
2925/**
3026 * Assert that `tree` is a valid hast node.
@@ -37,7 +33,7 @@ import {
3733 * Thing to assert.
3834 * @param {UnistParent | null | undefined } [parent]
3935 * Optional, valid parent.
40- * @returns {asserts tree is Node }
36+ * @returns {asserts tree is Nodes }
4137 * Nothing.
4238 * @throws {AssertionError }
4339 * When `tree` (or its descendants) is not a hast node.
@@ -57,7 +53,7 @@ export function assert(tree, parent) {
5753 * Thing to assert.
5854 * @param {UnistParent | null | undefined } [parent]
5955 * Optional, valid parent.
60- * @returns {asserts tree is Parent }
56+ * @returns {asserts tree is Parents }
6157 * Nothing.
6258 * @throws {AssertionError }
6359 * When `tree` is not a parent or its descendants are not nodes.
@@ -75,7 +71,7 @@ export function parent(tree, parent) {
7571 * Thing to assert.
7672 * @param {UnistParent | null | undefined } [parent]
7773 * Optional, valid parent.
78- * @returns {asserts node is Literal }
74+ * @returns {asserts node is Literals }
7975 * Nothing.
8076 * @throws {AssertionError }
8177 * When `node` is not a hast literal.
@@ -125,7 +121,7 @@ function unknown(node, parent) {
125121 *
126122 * @param {unknown } [tree]
127123 * Thing to assert.
128- * @returns {asserts tree is Parent }
124+ * @returns {asserts tree is Parents }
129125 * Nothing.
130126 * @throws {AssertionError }
131127 * When `tree` is not a parent or its descendants are not nodes.
@@ -142,7 +138,7 @@ function assertParent(tree) {
142138 *
143139 * @param {unknown } [node]
144140 * Thing to assert.
145- * @returns {asserts node is Literal }
141+ * @returns {asserts node is Literals }
146142 * Nothing.
147143 * @throws {AssertionError }
148144 * When `node` is not a hast literal.
@@ -192,18 +188,11 @@ function assertRoot(tree, parent) {
192188function assertElement ( tree ) {
193189 assertParent ( tree )
194190
195- nodeAssert . strictEqual (
196- // @ts -expect-error: hush.
197- typeof tree . tagName ,
198- 'string' ,
191+ nodeAssert . ok (
192+ 'tagName' in tree && typeof tree . tagName === 'string' ,
199193 '`element` should have a `tagName`'
200194 )
201- nodeAssert . notStrictEqual (
202- // @ts -expect-error: hush.
203- tree . tagName ,
204- '' ,
205- '`element.tagName` should not be empty'
206- )
195+ nodeAssert . ok ( tree . tagName !== '' , '`element.tagName` should not be empty' )
207196}
208197
209198export { _void , wrap } from 'unist-util-assert'
0 commit comments