Skip to content

Commit 7ca8974

Browse files
committed
Refactor to use @imports
1 parent 8f29f1e commit 7ca8974

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

lib/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/// <reference types="remark-parse" />
2-
/// <reference types="remark-stringify" />
3-
/// <reference types="mdast-util-directive" />
4-
51
/**
6-
* @typedef {import('mdast').Root} Root
7-
* @typedef {import('unified').Processor<Root>} Processor
2+
* @import {} from 'mdast-util-directive'
3+
* @import {Root} from 'mdast'
4+
* @import {} from 'remark-arse'
5+
* @import {} from 'remark-stringify'
6+
* @import {Processor} from 'unified'
87
*/
98

109
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
@@ -23,7 +22,7 @@ import {directive} from 'micromark-extension-directive'
2322
export default function remarkDirective() {
2423
// @ts-expect-error: TS is wrong about `this`.
2524
// eslint-disable-next-line unicorn/no-this-assignment
26-
const self = /** @type {Processor} */ (this)
25+
const self = /** @type {Processor<Root>} */ (this)
2726
const data = self.data()
2827

2928
const micromarkExtensions =

readme.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ A :i[lovely] language know as :abbr[HTML]{title="HyperText Markup Language"}.
104104
…and our module `example.js` contains:
105105

106106
```js
107-
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
108-
/// <reference types="mdast-util-to-hast" />
109-
// Register directive nodes in mdast:
110-
/// <reference types="mdast-util-directive" />
107+
/**
108+
* @import {} from 'mdast-util-directive'
109+
* @import {} from 'mdast-util-to-hast'
110+
* @import {Root} from 'mdast'
111+
*/
111112

112113
import {h} from 'hastscript'
113114
import rehypeFormat from 'rehype-format'
@@ -135,7 +136,7 @@ console.log(String(file))
135136
// See below for others examples.
136137
function myRemarkPlugin() {
137138
/**
138-
* @param {import('mdast').Root} tree
139+
* @param {Root} tree
139140
* Tree.
140141
* @returns {undefined}
141142
* Nothing.
@@ -199,19 +200,21 @@ It’s based on the example in Use above.
199200
If `myRemarkPlugin` was replaced with this function:
200201

201202
```js
202-
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
203-
/// <reference types="mdast-util-to-hast" />
204-
// Register directive nodes in mdast:
205-
/// <reference types="mdast-util-directive" />
203+
/**
204+
* @import {} from 'mdast-util-directive'
205+
* @import {} from 'mdast-util-to-hast'
206+
* @import {Root} from 'mdast'
207+
* @import {VFile} from 'vfile'
208+
*/
206209

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

209212
// This plugin is an example to turn `::youtube` into iframes.
210213
function myRemarkPlugin() {
211214
/**
212-
* @param {import('mdast').Root} tree
215+
* @param {Root} tree
213216
* Tree.
214-
* @param {import('vfile').VFile} file
217+
* @param {VFile} file
215218
* File.
216219
* @returns {undefined}
217220
* Nothing.
@@ -279,10 +282,11 @@ It’s based on the example in Use above.
279282
If `myRemarkPlugin` was replaced with this function:
280283

281284
```js
282-
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
283-
/// <reference types="mdast-util-to-hast" />
284-
// Register directive nodes in mdast:
285-
/// <reference types="mdast-util-directive" />
285+
/**
286+
* @import {} from 'mdast-util-directive'
287+
* @import {} from 'mdast-util-to-hast'
288+
* @import {Root} from 'mdast'
289+
*/
286290

287291
import {h} from 'hastscript'
288292
import {visit} from 'unist-util-visit'
@@ -291,7 +295,7 @@ import {visit} from 'unist-util-visit'
291295
// attributes.
292296
function myRemarkPlugin() {
293297
/**
294-
* @param {import('mdast').Root} tree
298+
* @param {Root} tree
295299
* Tree.
296300
* @returns {undefined}
297301
* Nothing.
@@ -372,14 +376,16 @@ If you’re working with the syntax tree, you can register the new node types
372376
with `@types/mdast` by adding a reference:
373377

374378
```js
375-
// Register directive nodes in mdast:
376-
/// <reference types="mdast-util-directive" />
379+
/**
380+
* @import {} from 'mdast-util-directive'
381+
* @import {Root} from 'mdast'
382+
*/
377383

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

380386
function myRemarkPlugin() {
381387
/**
382-
* @param {import('mdast').Root} tree
388+
* @param {Root} tree
383389
* Tree.
384390
* @returns {undefined}
385391
* Nothing.

0 commit comments

Comments
 (0)