Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 21, 2022
1 parent 4f54017 commit cb14568
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
/**
* @typedef {import('mdast').Content|import('mdast').Root} MdastNode
* @typedef {import('mdast').Content|import('mdast').Root} Node
*/

import {visit} from 'unist-util-visit'

/**
* Make an mdast tree compact by merging adjacent text nodes and block quotes.
*
* @template {MdastNode} Tree
* @template {Node} Tree
* @param {Tree} tree
* @returns {Tree}
*/
export function compact(tree) {
visit(tree, (child, index, parent) => {
// @ts-expect-error: hush, TS.
visit(tree, visitor)

return tree

/**
* @param {import('mdast').Content} child
* @param {number} index
* @param {Extract<Node, import('mdast').Parent>} parent
*/
function visitor(child, index, parent) {
if (
parent &&
index &&
Expand Down Expand Up @@ -40,7 +50,5 @@ export function compact(tree) {
return index
}
}
})

return tree
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand Down

0 comments on commit cb14568

Please sign in to comment.