1212 * @typedef {import('unist').Point } Point
1313 *
1414 * @typedef {import('hast').Root } Root
15- * @typedef {import('hast').DocType } Doctype
15+ * @typedef {import('hast').Doctype } Doctype
1616 * @typedef {import('hast').Element } Element
1717 * @typedef {import('hast').Text } Text
1818 * @typedef {import('hast').Comment } Comment
19- * @typedef {import('hast').Content } Content
19+ * @typedef {import('hast').RootContent } RootContent
20+ * @typedef {import('hast').Nodes } Nodes
2021 *
2122 * @typedef {import('mdast-util-to-hast').Raw } Raw
2223 */
2324
2425/**
25- * @typedef {Root | Content } Node
26- *
27- * @typedef {{type: 'comment', value: {stitch: Node}} } Stitch
26+ * @typedef {{type: 'comment', value: {stitch: Nodes}} } Stitch
2827 *
2928 * @typedef Options
3029 * Configuration.
4039 * Info passed around about the current state.
4140 * @property {Parser<DefaultTreeAdapterMap> } parser
4241 * Current parser.
43- * @property {(node: Node ) => void } handle
42+ * @property {(node: Nodes ) => void } handle
4443 * Add a hast node to the parser.
4544 * @property {boolean } stitches
4645 * Whether there are stitches.
@@ -75,16 +74,16 @@ const parseOptions = {sourceCodeLocationInfo: true, scriptingEnabled: false}
7574 * Pass a hast tree through an HTML parser, which will fix nesting, and turn
7675 * raw nodes into actual nodes.
7776 *
78- * @param {Node } tree
77+ * @param {Nodes } tree
7978 * Original hast tree to transform.
8079 * @param {Options | null | undefined } [options]
8180 * Configuration.
82- * @returns {Node }
81+ * @returns {Nodes }
8382 * Parsed again tree.
8483 */
8584export function raw ( tree , options ) {
8685 const document = documentMode ( tree )
87- /** @type {(node: Node , state: State) => void } */
86+ /** @type {(node: Nodes , state: State) => void } */
8887 const one = zwitch ( 'type' , {
8988 handlers : { root, element, text, comment, doctype, raw : handleRaw } ,
9089 unknown
@@ -137,7 +136,7 @@ export function raw(tree, options) {
137136/**
138137 * Transform all nodes
139138 *
140- * @param {Array<Content > } nodes
139+ * @param {Array<RootContent > } nodes
141140 * hast content.
142141 * @param {State } state
143142 * Info passed around about the current state.
@@ -247,7 +246,7 @@ function doctype(node, state) {
247246/**
248247 * Transform a stitch.
249248 *
250- * @param {Node } node
249+ * @param {Nodes } node
251250 * unknown node.
252251 * @param {State } state
253252 * Info passed around about the current state.
@@ -258,7 +257,7 @@ function stitch(node, state) {
258257 // Mark that there are stitches, so we need to walk the tree and revert them.
259258 state . stitches = true
260259
261- /** @type {Node } */
260+ /** @type {Nodes } */
262261 const clone = cloneWithoutChildren ( node )
263262
264263 // Recurse, because to somewhat handle `[<x>]</x>` (where `[]` denotes the
@@ -382,7 +381,7 @@ function handleRaw(node, state) {
382381 * Never.
383382 */
384383function unknown ( node_ , state ) {
385- const node = /** @type {Node } */ ( node_ )
384+ const node = /** @type {Nodes } */ ( node_ )
386385
387386 if (
388387 state . options . passThrough &&
@@ -406,7 +405,7 @@ function unknown(node_, state) {
406405 *
407406 * @param {State } state
408407 * Info passed around about the current state.
409- * @param {Point } point
408+ * @param {Point | undefined } point
410409 * Point.
411410 * @returns {void }
412411 * Nothing.
@@ -479,18 +478,13 @@ function resetTokenizer(state, point) {
479478 *
480479 * @param {State } state
481480 * Info passed around about the current state.
482- * @param {Point } point
481+ * @param {Point | undefined } point
483482 * Point.
484483 * @returns {void }
485484 * Nothing.
486485 */
487486function setPoint ( state , point ) {
488- if (
489- point . line &&
490- point . column &&
491- point . offset !== null &&
492- point . offset !== undefined
493- ) {
487+ if ( point && point . offset !== undefined ) {
494488 /** @type {Location } */
495489 const location = {
496490 startLine : point . line ,
@@ -646,7 +640,7 @@ function endTag(node, state) {
646640/**
647641 * Check if `node` represents a whole document or a fragment.
648642 *
649- * @param {Node } node
643+ * @param {Nodes } node
650644 * hast node.
651645 * @returns {boolean }
652646 * Whether this represents a whole document or a fragment.
@@ -663,7 +657,7 @@ function documentMode(node) {
663657/**
664658 * Get a `parse5` location from a node.
665659 *
666- * @param {Node | Stitch } node
660+ * @param {Nodes | Stitch } node
667661 * hast node.
668662 * @returns {Location }
669663 * `parse5` location.
@@ -673,19 +667,23 @@ function createParse5Location(node) {
673667 const end = pointEnd ( node )
674668
675669 return {
676- startLine : start . line ,
677- startCol : start . column ,
678670 // @ts -expect-error: could be `undefined` in hast, which `parse5` types don’t want.
679- startOffset : start . offset ,
680- endLine : end . line ,
681- endCol : end . column ,
671+ startLine : start ?. line ,
672+ // @ts -expect-error: could be `undefined` in hast, which `parse5` types don’t want.
673+ startCol : start ?. column ,
674+ // @ts -expect-error: could be `undefined` in hast, which `parse5` types don’t want.
675+ startOffset : start ?. offset ,
676+ // @ts -expect-error: could be `undefined` in hast, which `parse5` types don’t want.
677+ endLine : end ?. line ,
678+ // @ts -expect-error: could be `undefined` in hast, which `parse5` types don’t want.
679+ endCol : end ?. column ,
682680 // @ts -expect-error: could be `undefined` in hast, which `parse5` types don’t want.
683- endOffset : end . offset
681+ endOffset : end ? .offset
684682 }
685683}
686684
687685/**
688- * @template {Node } NodeType
686+ * @template {Nodes } NodeType
689687 * Node type.
690688 * @param {NodeType } node
691689 * Node to clone.
0 commit comments