From 8ed43dff3c531d8fca18f0ffd6c5b712aaaf01bd Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 24 Jun 2024 11:37:51 +0200 Subject: [PATCH] Refactor to use `@import`s --- packages/rehype-parse/lib/index.js | 10 +++++----- packages/rehype-stringify/lib/index.js | 10 +++++----- readme.md | 6 +++++- test/api.js | 4 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/rehype-parse/lib/index.js b/packages/rehype-parse/lib/index.js index 9e651a82..350fdd2e 100644 --- a/packages/rehype-parse/lib/index.js +++ b/packages/rehype-parse/lib/index.js @@ -1,7 +1,7 @@ /** - * @typedef {import('hast').Root} Root - * @typedef {import('hast-util-from-html').Options} FromHtmlOptions - * @typedef {import('unified').Parser} Parser + * @import {Root} from 'hast' + * @import {Options as FromHtmlOptions} from 'hast-util-from-html' + * @import {Parser, Processor} from 'unified' */ /** @@ -35,7 +35,7 @@ import {fromHtml} from 'hast-util-from-html' * Nothing. */ export default function rehypeParse(options) { - /** @type {import('unified').Processor} */ + /** @type {Processor} */ // @ts-expect-error: TS in JSDoc generates wrong types if `this` is typed regularly. const self = this const {emitParseErrors, ...settings} = {...self.data('settings'), ...options} @@ -43,7 +43,7 @@ export default function rehypeParse(options) { self.parser = parser /** - * @type {Parser} + * @type {Parser} */ function parser(document, file) { return fromHtml(document, { diff --git a/packages/rehype-stringify/lib/index.js b/packages/rehype-stringify/lib/index.js index 2060e7dc..8b9a78eb 100644 --- a/packages/rehype-stringify/lib/index.js +++ b/packages/rehype-stringify/lib/index.js @@ -1,7 +1,7 @@ /** - * @typedef {import('hast').Root} Root - * @typedef {import('hast-util-to-html').Options} Options - * @typedef {import('unified').Compiler} Compiler + * @import {Root} from 'hast' + * @import {Options} from 'hast-util-to-html' + * @import {Compiler, Processor} from 'unified' */ import {toHtml} from 'hast-util-to-html' @@ -15,7 +15,7 @@ import {toHtml} from 'hast-util-to-html' * Nothing. */ export default function rehypeStringify(options) { - /** @type {import('unified').Processor} */ + /** @type {Processor} */ // @ts-expect-error: TS in JSDoc generates wrong types if `this` is typed regularly. const self = this const settings = {...self.data('settings'), ...options} @@ -23,7 +23,7 @@ export default function rehypeStringify(options) { self.compiler = compiler /** - * @type {Compiler} + * @type {Compiler} */ function compiler(tree) { return toHtml(tree, settings) diff --git a/readme.md b/readme.md index 204e7af8..c21ee11f 100644 --- a/readme.md +++ b/readme.md @@ -106,6 +106,10 @@ With another plugin, you can turn this HTML:
Show example code ```js +/** + * @import {Root} from 'hast' + */ + import rehypeParse from 'rehype-parse' import rehypeStringify from 'rehype-stringify' import {unified} from 'unified' @@ -121,7 +125,7 @@ console.log(String(file)) function myRehypePluginToIncreaseHeadings() { /** - * @param {import('hast').Root} tree + * @param {Root} tree */ return function (tree) { visit(tree, 'element', function (node) { diff --git a/test/api.js b/test/api.js index 5f296e2a..bac2e11f 100644 --- a/test/api.js +++ b/test/api.js @@ -1,6 +1,6 @@ /** - * @typedef {import('unified').Settings} Settings - * @typedef {import('hast').Root} Root + * @import {Settings} from 'unified' + * @import {Root} from 'hast' */ import assert from 'node:assert/strict'