Skip to content

Commit

Permalink
Update unist-util-visit
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 30, 2021
1 parent 7987f71 commit d317e7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions lib/index.js
Expand Up @@ -128,7 +128,13 @@ export function raw(tree, file, options) {
const result = fromParse5(documentMode(tree) ? document() : fragment(), file)

if (stitches) {
visit(result, 'comment', mend)
visit(result, 'comment', (node, index, parent) => {
const stitch = /** @type {Stitch} */ (node)
if (stitch.value.stitch && parent !== null && index !== null) {
parent.children[index] = stitch.value.stitch
return index
}
})
}

// Unpack if possible and when not given a `root`.
Expand All @@ -142,16 +148,6 @@ export function raw(tree, file, options) {

return result

/**
* @type {import('unist-util-visit').Visitor<Stitch>}
*/
function mend(node, index, parent) {
if (node.value.stitch && parent !== null && index !== null) {
parent.children[index] = node.value.stitch
return index
}
}

/**
* @returns {P5Fragment}
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -42,7 +42,7 @@
"html-void-elements": "^2.0.0",
"parse5": "^6.0.0",
"unist-util-position": "^4.0.0",
"unist-util-visit": "^3.0.0",
"unist-util-visit": "^4.0.0",
"vfile": "^5.0.0",
"web-namespaces": "^2.0.0",
"zwitch": "^2.0.0"
Expand Down

0 comments on commit d317e7a

Please sign in to comment.