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 Jun 24, 2024
1 parent 43b5554 commit 8ca9469
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
11 changes: 5 additions & 6 deletions packages/remark-parse/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast-util-from-markdown').Options} FromMarkdownOptions
* @typedef {import('unified').Parser<Root>} Parser
* @typedef {import('unified').Processor<Root>} Processor
* @import {Root} from 'mdast'
* @import {Options as FromMarkdownOptions} from 'mdast-util-from-markdown'
* @import {Parser, Processor} from 'unified'
*/

/**
Expand All @@ -20,14 +19,14 @@ import {fromMarkdown} from 'mdast-util-from-markdown'
* Nothing.
*/
export default function remarkParse(options) {
/** @type {Processor} */
/** @type {Processor<Root>} */
// @ts-expect-error: TS in JSDoc generates wrong types if `this` is typed regularly.
const self = this

self.parser = parser

/**
* @type {Parser}
* @type {Parser<Root>}
*/
function parser(document) {
return fromMarkdown(document, {
Expand Down
11 changes: 5 additions & 6 deletions packages/remark-stringify/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownOptions
* @typedef {import('unified').Compiler<Root, string>} Compiler
* @typedef {import('unified').Processor<undefined, undefined, undefined, Root, string>} Processor
* @import {Root} from 'mdast'
* @import {Options as ToMarkdownOptions} from 'mdast-util-to-markdown'
* @import {Compiler, Processor} from 'unified'
*/

/**
Expand All @@ -20,14 +19,14 @@ import {toMarkdown} from 'mdast-util-to-markdown'
* Nothing.
*/
export default function remarkStringify(options) {
/** @type {Processor} */
/** @type {Processor<undefined, undefined, undefined, Root, string>} */
// @ts-expect-error: TS in JSDoc generates wrong types if `this` is typed regularly.
const self = this

self.compiler = compiler

/**
* @type {Compiler}
* @type {Compiler<Root, string>}
*/
function compiler(tree) {
return toMarkdown(tree, {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ For example:

```js
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('vfile').VFile} VFile
* @import {Root} from 'mdast'
* @import {VFile} from 'vfile'
*/

/**
Expand Down

0 comments on commit 8ca9469

Please sign in to comment.