Skip to content

Commit

Permalink
Refactor to use @imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 16, 2024
1 parent 2556c0b commit 308400c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
17 changes: 7 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Properties} Properties
* @typedef {import('hast').Root} Root
*
* @typedef {import('hast-util-is-element').Test} Test
* @import {Test} from 'hast-util-is-element'
* @import {ElementContent, Element, Properties, Root} from 'hast'
* @import {Visitor} from 'unist-util-visit'
*/

/**
Expand Down Expand Up @@ -106,7 +103,7 @@ export default function rehypeAutolinkHeadings(options) {
const group = settings.group
const is = convertElement(settings.test)

/** @type {import('unist-util-visit').Visitor<Element>} */
/** @type {Visitor<Element>} */
let method

if (behavior === 'after' || behavior === 'before') {
Expand Down Expand Up @@ -138,7 +135,7 @@ export default function rehypeAutolinkHeadings(options) {
})
}

/** @type {import('unist-util-visit').Visitor<Element>} */
/** @type {Visitor<Element>} */
function inject(node) {
const children = toChildren(content || contentDefaults, node)
node.children[behavior === 'prepend' ? 'unshift' : 'push'](
Expand All @@ -148,7 +145,7 @@ export default function rehypeAutolinkHeadings(options) {
return [SKIP]
}

/** @type {import('unist-util-visit').Visitor<Element>} */
/** @type {Visitor<Element>} */
function around(node, index, parent) {
/* c8 ignore next -- uncommon */
if (typeof index !== 'number' || !parent) return
Expand All @@ -171,7 +168,7 @@ export default function rehypeAutolinkHeadings(options) {
return [SKIP, index + nodes.length]
}

/** @type {import('unist-util-visit').Visitor<Element>} */
/** @type {Visitor<Element>} */
function wrap(node) {
/** @type {Array<ElementContent>} */
let before = node.children
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ build nodes from a string of HTML.

```js
/**
* @typedef {import('hast').ElementContent} ElementContent
* @import {ElementContent} from 'hast'
*/

import {fromHtmlIsomorphic} from 'hast-util-from-html-isomorphic'
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import('rehype-autolink-headings').Options} Options
* @import {Options} from 'rehype-autolink-headings'
*/

import assert from 'node:assert/strict'
Expand Down

0 comments on commit 308400c

Please sign in to comment.