Skip to content

Commit 15a4a6b

Browse files
committed
Refactor JSDoc
1 parent 227b18b commit 15a4a6b

File tree

7 files changed

+28
-22
lines changed

7 files changed

+28
-22
lines changed

lib/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
/**
2-
* @typedef {import('vfile').VFile} VFile
3-
* @typedef {import('nlcst').Parent} Parent
42
* @typedef {import('nlcst').Content} Content
5-
* @typedef {import('nlcst').SentenceContent} SentenceContent
6-
* @typedef {import('nlcst').Root} Root
73
* @typedef {import('nlcst').Paragraph} Paragraph
4+
* @typedef {import('nlcst').Parent} Parent
5+
* @typedef {import('nlcst').Root} Root
86
* @typedef {import('nlcst').Sentence} Sentence
7+
* @typedef {import('nlcst').SentenceContent} SentenceContent
8+
* @typedef {import('vfile').VFile} VFile
9+
*/
10+
11+
/**
12+
* @typedef {Content | Root} Nodes
13+
* @typedef {Extract<Nodes, Parent>} Parents
914
*/
1015

1116
/**
@@ -60,6 +65,7 @@ export class ParseLatin {
6065
constructor(doc, file) {
6166
const value = file || doc
6267

68+
// To do: next major: use `undefined`.
6369
/** @type {string | null} */
6470
this.doc = value ? String(value) : null
6571

@@ -296,19 +302,19 @@ ParseLatin.prototype.tokenizeRootPlugins = [
296302
/**
297303
* A function that splits one node into several nodes.
298304
*
299-
* @template {Parent} TheNode
305+
* @template {Parents} Node
300306
* Node type.
301-
* @param {TheNode} node
307+
* @param {Node} node
302308
* Node to split.
303309
* @param {RegExp} expression
304310
* Split on this regex.
305311
* @param {Content['type']} childType
306312
* Split this node type.
307-
* @returns {Array<TheNode>}
313+
* @returns {Array<Node>}
308314
* The given node, split into several nodes.
309315
*/
310316
function splitNode(node, childType, expression) {
311-
/** @type {Array<TheNode>} */
317+
/** @type {Array<Node>} */
312318
const result = []
313319
let index = -1
314320
let start = 0
@@ -320,7 +326,7 @@ function splitNode(node, childType, expression) {
320326
index === node.children.length - 1 ||
321327
(token.type === childType && expression.test(toString(token)))
322328
) {
323-
/** @type {TheNode} */
329+
/** @type {Node} */
324330
// @ts-expect-error: fine
325331
const parent = {
326332
type: node.type,

lib/plugin/make-final-white-space-siblings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('nlcst').Root} Root
32
* @typedef {import('nlcst').Paragraph} Paragraph
3+
* @typedef {import('nlcst').Root} Root
44
*/
55

66
import {modifyChildren} from 'unist-util-modify-children'

lib/plugin/make-initial-white-space-siblings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('nlcst').Root} Root
32
* @typedef {import('nlcst').Paragraph} Paragraph
3+
* @typedef {import('nlcst').Root} Root
44
*/
55

66
import {visitChildren} from 'unist-util-visit-children'

lib/plugin/merge-inner-word-slash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2+
* @typedef {import('nlcst').Sentence} Sentence
23
* @typedef {import('nlcst').SentenceContent} SentenceContent
34
* @typedef {import('nlcst').WordContent} WordContent
4-
* @typedef {import('nlcst').Sentence} Sentence
55
*/
66

77
import {toString} from 'nlcst-to-string'

lib/plugin/patch-position.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
2-
* @typedef {import('unist').Node} Node
3-
* @typedef {import('nlcst').Sentence} Sentence
42
* @typedef {import('nlcst').Paragraph} Paragraph
3+
* @typedef {import('nlcst').Sentence} Sentence
54
* @typedef {import('nlcst').Root} Root
5+
* @typedef {import('unist').Node} Node
6+
* @typedef {import('unist').Position} Position
67
*/
78

89
import {visitChildren} from 'unist-util-visit-children'
@@ -22,7 +23,6 @@ export const patchPosition = visitChildren(
2223
(!node.position || !node.position.start)
2324
) {
2425
patch(node)
25-
// @ts-expect-error: we just set it.
2626
node.position.start = child.position.start
2727
}
2828

@@ -32,18 +32,18 @@ export const patchPosition = visitChildren(
3232
(!node.position || !node.position.end)
3333
) {
3434
patch(node)
35-
// @ts-expect-error: we just set it.
3635
node.position.end = child.position.end
3736
}
3837
}
3938
)
4039

4140
/**
4241
* @param {Node} node
42+
* @returns {asserts node is Node & {position: Position}}
4343
*/
4444
function patch(node) {
4545
if (!node.position) {
46-
// @ts-expect-error: fine.
46+
// @ts-expect-error: fine, we’ll fill it later.
4747
node.position = {}
4848
}
4949
}

lib/plugin/remove-empty-nodes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
* @typedef {import('nlcst').Root} Root
32
* @typedef {import('nlcst').Paragraph} Paragraph
3+
* @typedef {import('nlcst').Root} Root
44
*/
55

66
import {modifyChildren} from 'unist-util-modify-children'
77

88
// Remove empty children.
99
export const removeEmptyNodes = modifyChildren(
1010
/**
11-
* @type {import('unist-util-modify-children').Modifier<Root | Paragraph>}
11+
* @type {import('unist-util-modify-children').Modifier<Paragraph | Root>}
1212
*/
1313

1414
function (child, index, parent) {

test/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,12 @@ test('Abbreviations: Initialisms', async function (t) {
12351235
*
12361236
* @param {string} name
12371237
* @param {string} doc
1238-
* @param {'parse' | 'tokenizeParagraph' | 'tokenizeRoot' | 'tokenizeSentence'} [method='parse']
1239-
* @returns {Promise<void>}
1238+
* @param {'parse' | 'tokenizeParagraph' | 'tokenizeRoot' | 'tokenizeSentence' | undefined} [method='parse']
1239+
* @returns {Promise<undefined>}
12401240
*/
12411241
async function describeFixture(name, doc, method = 'parse') {
12421242
const nlcstA = latin[method](doc)
1243-
/** @type {Root | Content} */
1243+
/** @type {Content | Root} */
12441244
const fixture = JSON.parse(
12451245
String(await fs.readFile(path.join('test', 'fixture', name + '.json')))
12461246
)

0 commit comments

Comments
 (0)