Skip to content

Commit f539dd2

Browse files
committed
Add JSDoc based types
1 parent 889e9e1 commit f539dd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+684
-205
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
coverage/
22
node_modules/
3+
*.d.ts
34
*.log
45
.DS_Store
56
yarn.lock

.remarkignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/configure.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
/**
2+
* @typedef {import('./types.js').Options} Options
3+
* @typedef {import('./types.js').Context} Context
4+
*/
5+
6+
/**
7+
* @param {Context} base
8+
* @param {Options} extension
9+
* @returns {Context}
10+
*/
111
export function configure(base, extension) {
212
let index = -1
13+
/** @type {string} */
314
let key
415

516
// First do subextensions.
@@ -13,10 +24,13 @@ export function configure(base, extension) {
1324
if (key === 'extensions') {
1425
// Empty.
1526
} else if (key === 'unsafe' || key === 'join') {
16-
base[key] = base[key].concat(extension[key] || [])
27+
/* c8 ignore next 2 */
28+
// @ts-expect-error: hush.
29+
base[key] = [...(base[key] || []), ...(extension[key] || [])]
1730
} else if (key === 'handlers') {
1831
base[key] = Object.assign(base[key], extension[key] || {})
1932
} else {
33+
// @ts-expect-error: hush.
2034
base.options[key] = extension[key]
2135
}
2236
}

lib/handle/blockquote.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
/**
2+
* @typedef {import('mdast').Blockquote} Blockquote
3+
* @typedef {import('../types.js').Handle} Handle
4+
* @typedef {import('../util/indent-lines.js').Map} Map
5+
*/
6+
17
import {containerFlow} from '../util/container-flow.js'
28
import {indentLines} from '../util/indent-lines.js'
39

10+
/**
11+
* @type {Handle}
12+
* @param {Blockquote} node
13+
*/
414
export function blockquote(node, _, context) {
515
const exit = context.enter('blockquote')
616
const value = indentLines(containerFlow(node, context), map)
717
exit()
818
return value
919
}
1020

11-
function map(line, index, blank) {
21+
/** @type {Map} */
22+
function map(line, _, blank) {
1223
return '>' + (blank ? '' : ' ') + line
1324
}

lib/handle/break.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
/**
2+
* @typedef {import('../types.js').Handle} Handle
3+
*/
4+
15
import {patternInScope} from '../util/pattern-in-scope.js'
26

3-
export function hardBreak(node, _, context, safe) {
7+
/**
8+
* @type {Handle}
9+
*/
10+
export function hardBreak(_, _1, context, safe) {
411
let index = -1
512

613
while (++index < context.unsafe.length) {

lib/handle/code.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1+
/**
2+
* @typedef {import('mdast').Code} Code
3+
* @typedef {import('../types.js').Handle} Handle
4+
* @typedef {import('../types.js').Exit} Exit
5+
* @typedef {import('../util/indent-lines.js').Map} Map
6+
*/
7+
18
import {longestStreak} from 'longest-streak'
29
import {formatCodeAsIndented} from '../util/format-code-as-indented.js'
310
import {checkFence} from '../util/check-fence.js'
411
import {indentLines} from '../util/indent-lines.js'
512
import {safe} from '../util/safe.js'
613

14+
/**
15+
* @type {Handle}
16+
* @param {Code} node
17+
*/
718
export function code(node, _, context) {
819
const marker = checkFence(context)
920
const raw = node.value || ''
1021
const suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
22+
/** @type {string} */
1123
let value
24+
/** @type {Exit} */
1225
let exit
1326

1427
if (formatCodeAsIndented(node, context)) {
1528
exit = context.enter('codeIndented')
1629
value = indentLines(raw, map)
1730
} else {
1831
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3))
32+
/** @type {Exit} */
1933
let subexit
2034
exit = context.enter('codeFenced')
2135
value = sequence
@@ -55,6 +69,7 @@ export function code(node, _, context) {
5569
return value
5670
}
5771

72+
/** @type {Map} */
5873
function map(line, _, blank) {
5974
return (blank ? '' : ' ') + line
6075
}

lib/handle/definition.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
/**
2+
* @typedef {import('mdast').Definition} Definition
3+
* @typedef {import('../types.js').Handle} Handle
4+
*/
5+
16
import {association} from '../util/association.js'
27
import {checkQuote} from '../util/check-quote.js'
38
import {safe} from '../util/safe.js'
49

10+
/**
11+
* @type {Handle}
12+
* @param {Definition} node
13+
*/
514
export function definition(node, _, context) {
615
const marker = checkQuote(context)
716
const suffix = marker === '"' ? 'Quote' : 'Apostrophe'

lib/handle/emphasis.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @typedef {import('mdast').Emphasis} Emphasis
3+
* @typedef {import('../types.js').Handle} Handle
4+
*/
5+
16
import {checkEmphasis} from '../util/check-emphasis.js'
27
import {containerPhrasing} from '../util/container-phrasing.js'
38

@@ -7,6 +12,10 @@ emphasis.peek = emphasisPeek
712
// previous or next character of sequences.
813
// There’s no way around that though, except for injecting zero-width stuff.
914
// Do we need to safeguard against that?
15+
/**
16+
* @type {Handle}
17+
* @param {Emphasis} node
18+
*/
1019
export function emphasis(node, _, context) {
1120
const marker = checkEmphasis(context)
1221
const exit = context.enter('emphasis')
@@ -18,6 +27,9 @@ export function emphasis(node, _, context) {
1827
return marker + value + marker
1928
}
2029

21-
function emphasisPeek(node, _, context) {
30+
/**
31+
* @type {Handle}
32+
*/
33+
function emphasisPeek(_, _1, context) {
2234
return context.options.emphasis || '*'
2335
}

lib/handle/heading.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
/**
2+
* @typedef {import('mdast').Heading} Heading
3+
* @typedef {import('../types.js').Handle} Handle
4+
* @typedef {import('../types.js').Exit} Exit
5+
*/
6+
17
import {formatHeadingAsSetext} from '../util/format-heading-as-setext.js'
28
import {containerPhrasing} from '../util/container-phrasing.js'
39

10+
/**
11+
* @type {Handle}
12+
* @param {Heading} node
13+
*/
414
export function heading(node, _, context) {
515
const rank = Math.max(Math.min(6, node.depth || 1), 1)
16+
/** @type {Exit} */
617
let exit
18+
/** @type {Exit} */
719
let subexit
20+
/** @type {string} */
821
let value
922

1023
if (formatHeadingAsSetext(node, context)) {

lib/handle/html.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
/**
2+
* @typedef {import('mdast').HTML} HTML
3+
* @typedef {import('../types.js').Handle} Handle
4+
*/
5+
16
html.peek = htmlPeek
27

8+
/**
9+
* @type {Handle}
10+
* @param {HTML} node
11+
*/
312
export function html(node) {
413
return node.value || ''
514
}
615

16+
/**
17+
* @type {Handle}
18+
*/
719
function htmlPeek() {
820
return '<'
921
}

0 commit comments

Comments
 (0)