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
}

lib/handle/image-reference.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
/**
2+
* @typedef {import('mdast').ImageReference} ImageReference
3+
* @typedef {import('../types.js').Handle} Handle
4+
*/
5+
16
import {association} from '../util/association.js'
27
import {safe} from '../util/safe.js'
38

49
imageReference.peek = imageReferencePeek
510

11+
/**
12+
* @type {Handle}
13+
* @param {ImageReference} node
14+
*/
615
export function imageReference(node, _, context) {
716
const type = node.referenceType
817
const exit = context.enter('imageReference')
@@ -29,6 +38,9 @@ export function imageReference(node, _, context) {
2938
return value
3039
}
3140

41+
/**
42+
* @type {Handle}
43+
*/
3244
function imageReferencePeek() {
3345
return '!'
3446
}

lib/handle/image.js

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

49
image.peek = imagePeek
510

11+
/**
12+
* @type {Handle}
13+
* @param {Image} node
14+
*/
615
export function image(node, _, context) {
716
const quote = checkQuote(context)
817
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
@@ -47,6 +56,9 @@ export function image(node, _, context) {
4756
return value
4857
}
4958

59+
/**
60+
* @type {Handle}
61+
*/
5062
function imagePeek() {
5163
return '!'
5264
}

lib/handle/inline-code.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
/**
2+
* @typedef {import('mdast').InlineCode} InlineCode
3+
* @typedef {import('../types.js').Handle} Handle
4+
*/
5+
16
import {patternCompile} from '../util/pattern-compile.js'
27

38
inlineCode.peek = inlineCodePeek
49

5-
export function inlineCode(node, parent, context) {
10+
/**
11+
* @type {Handle}
12+
* @param {InlineCode} node
13+
*/
14+
export function inlineCode(node, _, context) {
615
let value = node.value || ''
716
let sequence = '`'
817
let index = -1
@@ -34,6 +43,7 @@ export function inlineCode(node, parent, context) {
3443
while (++index < context.unsafe.length) {
3544
const pattern = context.unsafe[index]
3645
const expression = patternCompile(pattern)
46+
/** @type {RegExpExecArray|null} */
3747
let match
3848

3949
// Only look for `atBreak`s.
@@ -59,6 +69,9 @@ export function inlineCode(node, parent, context) {
5969
return sequence + value + sequence
6070
}
6171

72+
/**
73+
* @type {Handle}
74+
*/
6275
function inlineCodePeek() {
6376
return '`'
6477
}

lib/handle/link-reference.js

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

510
linkReference.peek = linkReferencePeek
611

12+
/**
13+
* @type {Handle}
14+
* @param {LinkReference} node
15+
*/
716
export function linkReference(node, _, context) {
817
const type = node.referenceType
918
const exit = context.enter('linkReference')
@@ -30,6 +39,9 @@ export function linkReference(node, _, context) {
3039
return value
3140
}
3241

42+
/**
43+
* @type {Handle}
44+
*/
3345
function linkReferencePeek() {
3446
return '['
3547
}

lib/handle/link.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
/**
2+
* @typedef {import('mdast').Link} Link
3+
* @typedef {import('../types.js').Handle} Handle
4+
* @typedef {import('../types.js').Exit} Exit
5+
*/
6+
17
import {checkQuote} from '../util/check-quote.js'
28
import {formatLinkAsAutolink} from '../util/format-link-as-autolink.js'
39
import {containerPhrasing} from '../util/container-phrasing.js'
410
import {safe} from '../util/safe.js'
511

612
link.peek = linkPeek
713

14+
/**
15+
* @type {Handle}
16+
* @param {Link} node
17+
*/
818
export function link(node, _, context) {
919
const quote = checkQuote(context)
1020
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
21+
/** @type {Exit} */
1122
let exit
23+
/** @type {Exit} */
1224
let subexit
25+
/** @type {string} */
1326
let value
1427

1528
if (formatLinkAsAutolink(node, context)) {
@@ -65,6 +78,10 @@ export function link(node, _, context) {
6578
return value
6679
}
6780

81+
/**
82+
* @type {Handle}
83+
* @param {Link} node
84+
*/
6885
function linkPeek(node, _, context) {
6986
return formatLinkAsAutolink(node, context) ? '<' : '['
7087
}

0 commit comments

Comments
 (0)