Skip to content

Commit 0f26ecf

Browse files
committed
Refactor to use @import
1 parent 77364ee commit 0f26ecf

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

lib/index.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
/**
2-
* @typedef {import('trough').Pipeline} Pipeline
3-
*
4-
* @typedef {import('unist').Node} Node
5-
*
6-
* @typedef {import('vfile').Compatible} Compatible
7-
* @typedef {import('vfile').Value} Value
8-
*
9-
* @typedef {import('../index.js').CompileResultMap} CompileResultMap
10-
* @typedef {import('../index.js').Data} Data
11-
* @typedef {import('../index.js').Settings} Settings
2+
* @import {Pipeline} from 'trough'
3+
* @import {CompileResultMap, Data, Settings} from 'unified'
4+
* @import {Node} from 'unist'
5+
* @import {Compatible, Value} from 'vfile'
126
*/
137

148
/**

readme.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -1129,14 +1129,18 @@ See [`Transformer`][api-transformer] for more info.
11291129
`move.js`:
11301130
11311131
```js
1132+
/**
1133+
* @import {Plugin} from 'unified'
1134+
*/
1135+
11321136
/**
11331137
* @typedef Options
11341138
* Configuration (required).
11351139
* @property {string} extname
11361140
* File extension to use (must start with `.`).
11371141
*/
11381142

1139-
/** @type {import('unified').Plugin<[Options]>} */
1143+
/** @type {Plugin<[Options]>} */
11401144
export function move(options) {
11411145
if (!options || !options.extname) {
11421146
throw new Error('Missing `options.extname`')
@@ -1229,13 +1233,17 @@ They can contain plugins and settings.
12291233
`preset.js`:
12301234
12311235
```js
1236+
/**
1237+
* @import {Preset} from 'unified'
1238+
*/
1239+
12321240
import remarkCommentConfig from 'remark-comment-config'
12331241
import remarkLicense from 'remark-license'
12341242
import remarkPresetLintConsistent from 'remark-preset-lint-consistent'
12351243
import remarkPresetLintRecommended from 'remark-preset-lint-recommended'
12361244
import remarkToc from 'remark-toc'
12371245

1238-
/** @type {import('unified').Preset} */
1246+
/** @type {Preset} */
12391247
const preset = {
12401248
plugins: [
12411249
remarkPresetLintRecommended,
@@ -1493,8 +1501,9 @@ node types for the syntax trees provided by our packages (as in,
14931501
14941502
```js
14951503
/**
1496-
* @typedef {import('hast').Root} HastRoot
1497-
* @typedef {import('mdast').Root} MdastRoot
1504+
* @import {Root as HastRoot} from 'hast'
1505+
* @import {Root as MdastRoot} from 'mdast'
1506+
* @import {Plugin} from 'unified'
14981507
*/
14991508

15001509
/**
@@ -1505,22 +1514,22 @@ node types for the syntax trees provided by our packages (as in,
15051514
*/
15061515

15071516
// To type options:
1508-
/** @type {import('unified').Plugin<[(Options | null | undefined)?]>} */
1517+
/** @type {Plugin<[(Options | null | undefined)?]>} */
15091518
export function myPluginAcceptingOptions(options) {
15101519
const settings = options || {}
15111520
// `settings` is now `Options`.
15121521
}
15131522

15141523
// To type a plugin that works on a certain tree, without options:
1515-
/** @type {import('unified').Plugin<[], MdastRoot>} */
1524+
/** @type {Plugin<[], MdastRoot>} */
15161525
export function myRemarkPlugin() {
15171526
return function (tree, file) {
15181527
// `tree` is `MdastRoot`.
15191528
}
15201529
}
15211530

15221531
// To type a plugin that transforms one tree into another:
1523-
/** @type {import('unified').Plugin<[], MdastRoot, HastRoot>} */
1532+
/** @type {Plugin<[], MdastRoot, HastRoot>} */
15241533
export function remarkRehype() {
15251534
return function (tree) {
15261535
// `tree` is `MdastRoot`.
@@ -1529,11 +1538,11 @@ export function remarkRehype() {
15291538
}
15301539

15311540
// To type a plugin that defines a parser:
1532-
/** @type {import('unified').Plugin<[], string, MdastRoot>} */
1541+
/** @type {Plugin<[], string, MdastRoot>} */
15331542
export function remarkParse(options) {}
15341543

15351544
// To type a plugin that defines a compiler:
1536-
/** @type {import('unified').Plugin<[], HastRoot, string>} */
1545+
/** @type {Plugin<[], HastRoot, string>} */
15371546
export function rehypeStringify(options) {}
15381547
```
15391548

test/freeze.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @import {Plugin} from 'unified'
3+
* @import {Node} from 'unist'
4+
*/
5+
16
import assert from 'node:assert/strict'
27
import test from 'node:test'
38
import {unified} from 'unified'
@@ -217,15 +222,15 @@ test('`freeze`', async function (t) {
217222

218223
// `this` in JS is buggy in TS.
219224
/**
220-
* @type {import('unified').Plugin<[], string, import('unist').Node>}
225+
* @type {Plugin<[], string, Node>}
221226
*/
222227
function parse() {
223228
this.parser = simpleParser
224229
}
225230

226231
// `this` in JS is buggy in TS.
227232
/**
228-
* @type {import('unified').Plugin<[], import('unist').Node, string>}
233+
* @type {Plugin<[], Node, string>}
229234
*/
230235
function compile() {
231236
this.compiler = simpleCompiler

test/parse.js

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @typedef {import('unist').Node} Node
3-
*/
4-
51
import assert from 'node:assert/strict'
62
import test from 'node:test'
73
import {unified} from 'unified'

test/process-sync.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @import {Plugin} from 'unified'
3+
* @import {Node} from 'unist'
4+
*/
5+
16
import assert from 'node:assert/strict'
27
import test from 'node:test'
38
import {unified} from 'unified'
@@ -61,15 +66,15 @@ test('`processSync`', async function (t) {
6166

6267
// `this` in JS is buggy in TS.
6368
/**
64-
* @type {import('unified').Plugin<[], string, import('unist').Node>}
69+
* @type {Plugin<[], string, Node>}
6570
*/
6671
function parse() {
6772
this.parser = simpleParser
6873
}
6974

7075
// `this` in JS is buggy in TS.
7176
/**
72-
* @type {import('unified').Plugin<[], import('unist').Node, string>}
77+
* @type {Plugin<[], Node, string>}
7378
*/
7479
function compile() {
7580
this.compiler = simpleCompiler

test/stringify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('unist').Node} Node
2+
* @import {Node} from 'unist'
33
*/
44

55
import assert from 'node:assert/strict'

test/util/simple.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
2-
* @typedef {import('unist').Node} Node
3-
* @typedef {import('unist').Literal} Literal
2+
* @import {Literal, Node} from 'unist'
43
*/
54

65
// Make references to the above types visible in VS Code.

0 commit comments

Comments
 (0)