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 Oct 3, 2024
1 parent 73b5852 commit 79f0306
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
7 changes: 4 additions & 3 deletions packages/retext-dutch/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @typedef {import('nlcst').Root} Root
* @import {Root} from 'nlcst'
* @import {Parser, Processor} from 'unified'
*/

import {ParseDutch} from 'parse-dutch'
Expand All @@ -13,11 +14,11 @@ import {ParseDutch} from 'parse-dutch'
export default function retextDutch() {
// @ts-expect-error -- TS in JSDoc doesn’t understand `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {import('unified').Processor<Root>} */ (this)
const self = /** @type {Processor<Root>} */ (this)

self.parser = parser

/** @type {import('unified').Parser<Root>} */
/** @type {Parser<Root>} */
function parser(value) {
const parser = new ParseDutch()
add(parser.tokenizeParagraphPlugins, self.data('nlcstParagraphExtensions'))
Expand Down
7 changes: 4 additions & 3 deletions packages/retext-english/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @typedef {import('nlcst').Root} Root
* @import {Root} from 'nlcst'
* @import {Parser, Processor} from 'unified'
*/

import {ParseEnglish} from 'parse-english'
Expand All @@ -13,11 +14,11 @@ import {ParseEnglish} from 'parse-english'
export default function retextEnglish() {
// @ts-expect-error -- TS in JSDoc doesn’t understand `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {import('unified').Processor<Root>} */ (this)
const self = /** @type {Processor<Root>} */ (this)

self.parser = parser

/** @type {import('unified').Parser<Root>} */
/** @type {Parser<Root>} */
function parser(value) {
const parser = new ParseEnglish()
add(parser.tokenizeParagraphPlugins, self.data('nlcstParagraphExtensions'))
Expand Down
7 changes: 4 additions & 3 deletions packages/retext-latin/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @typedef {import('nlcst').Root} Root
* @import {Root} from 'nlcst'
* @import {Parser, Processor} from 'unified'
*/

import {ParseLatin} from 'parse-latin'
Expand All @@ -13,11 +14,11 @@ import {ParseLatin} from 'parse-latin'
export default function retextLatin() {
// @ts-expect-error -- TS in JSDoc doesn’t understand `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {import('unified').Processor<Root>} */ (this)
const self = /** @type {Processor<Root>} */ (this)

self.parser = parser

/** @type {import('unified').Parser<Root>} */
/** @type {Parser<Root>} */
function parser(value) {
const parser = new ParseLatin()
add(parser.tokenizeParagraphPlugins, self.data('nlcstParagraphExtensions'))
Expand Down
7 changes: 4 additions & 3 deletions packages/retext-stringify/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @typedef {import('nlcst').Root} Root
* @import {Root} from 'nlcst'
* @import {Compiler, Processor} from 'unified'
*/

import {toString} from 'nlcst-to-string'
Expand All @@ -13,15 +14,15 @@ import {toString} from 'nlcst-to-string'
export default function retextStringify() {
// eslint-disable-next-line unicorn/no-this-assignment
const self =
/** @type {import('unified').Processor<undefined, undefined, undefined, Root, string>} */ (
/** @type {Processor<undefined, undefined, undefined, Root, string>} */ (
// @ts-expect-error -- TS in JSDoc doesn’t understand `this`.
this
)

self.compiler = compiler
}

/** @type {import('unified').Compiler<Root, string>} */
/** @type {Compiler<Root, string>} */
function compiler(tree) {
return toString(tree)
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ For example:

```js
/**
* @typedef {import('nlcst').Root} Root
* @import {Root} from 'nlcst'
*/

/**
Expand Down
5 changes: 3 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @typedef {import('nlcst').Root} Root
* @import {Root} from 'nlcst'
* @import {Plugin} from 'unified'
*/

import assert from 'node:assert/strict'
Expand Down Expand Up @@ -85,7 +86,7 @@ async function eachParser(name) {
const id = 'retext-' + name

await test(id, async function (t) {
/** @type {{default: import('unified').Plugin<[], string, Root>}} */
/** @type {{default: Plugin<[], string, Root>}} */
const result = await import(id)

await t.test('should expose the public api', async function () {
Expand Down

0 comments on commit 79f0306

Please sign in to comment.