Skip to content

Commit 8058792

Browse files
committed
Refactor types
1 parent 767ef62 commit 8058792

28 files changed

+333
-221
lines changed

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
/**
2-
* @typedef {import('./lib/types.js').SafeOptions} SafeOptions
2+
* @typedef {import('./lib/types.js').Info} SafeOptions
3+
* To do: remove next major: renamed because it doesn’t really reflect
4+
* options, but instead info on the surrounding of the generated thing.
5+
*/
6+
7+
/**
8+
* @typedef {import('./lib/types.js').Info} Info
39
* @typedef {import('./lib/types.js').Context} Context
410
* @typedef {import('./lib/types.js').Handle} Handle
511
* @typedef {import('./lib/types.js').Handlers} Handlers

lib/handle/blockquote.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/**
22
* @typedef {import('mdast').Blockquote} Blockquote
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
* @typedef {import('../util/indent-lines.js').Map} Map
107
*/
118

@@ -15,14 +12,14 @@ import {track} from '../util/track.js'
1512

1613
/**
1714
* @param {Blockquote} node
18-
* @param {Parent|undefined} _
15+
* @param {Parent | undefined} _
1916
* @param {Context} context
20-
* @param {SafeOptions} safeOptions
17+
* @param {Info} info
2118
* @returns {string}
2219
*/
23-
export function blockquote(node, _, context, safeOptions) {
20+
export function blockquote(node, _, context, info) {
2421
const exit = context.enter('blockquote')
25-
const tracker = track(safeOptions)
22+
const tracker = track(info)
2623
tracker.move('> ')
2724
tracker.shift(2)
2825
const value = indentLines(

lib/handle/break.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
/**
22
* @typedef {import('mdast').Break} Break
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
*/
107

118
import {patternInScope} from '../util/pattern-in-scope.js'
129

1310
/**
1411
* @param {Break} _
15-
* @param {Parent|undefined} _1
12+
* @param {Parent | undefined} _1
1613
* @param {Context} context
17-
* @param {SafeOptions} safeOptions
14+
* @param {Info} info
1815
* @returns {string}
1916
*/
20-
export function hardBreak(_, _1, context, safeOptions) {
17+
export function hardBreak(_, _1, context, info) {
2118
let index = -1
2219

2320
while (++index < context.unsafe.length) {
@@ -27,7 +24,7 @@ export function hardBreak(_, _1, context, safeOptions) {
2724
context.unsafe[index].character === '\n' &&
2825
patternInScope(context.stack, context.unsafe[index])
2926
) {
30-
return /[ \t]/.test(safeOptions.before) ? '' : ' '
27+
return /[ \t]/.test(info.before) ? '' : ' '
3128
}
3229
}
3330

lib/handle/code.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/**
22
* @typedef {import('mdast').Code} Code
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
* @typedef {import('../util/indent-lines.js').Map} Map
107
*/
118

@@ -18,12 +15,12 @@ import {track} from '../util/track.js'
1815

1916
/**
2017
* @param {Code} node
21-
* @param {Parent|undefined} _
18+
* @param {Parent | undefined} _
2219
* @param {Context} context
23-
* @param {SafeOptions} safeOptions
20+
* @param {Info} info
2421
* @returns {string}
2522
*/
26-
export function code(node, _, context, safeOptions) {
23+
export function code(node, _, context, info) {
2724
const marker = checkFence(context)
2825
const raw = node.value || ''
2926
const suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
@@ -35,7 +32,7 @@ export function code(node, _, context, safeOptions) {
3532
return value
3633
}
3734

38-
const tracker = track(safeOptions)
35+
const tracker = track(info)
3936
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3))
4037
const exit = context.enter('codeFenced')
4138
let value = tracker.move(sequence)

lib/handle/definition.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/**
22
* @typedef {import('mdast').Definition} Definition
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
*/
107

118
import {association} from '../util/association.js'
@@ -15,17 +12,17 @@ import {track} from '../util/track.js'
1512

1613
/**
1714
* @param {Definition} node
18-
* @param {Parent|undefined} _
15+
* @param {Parent | undefined} _
1916
* @param {Context} context
20-
* @param {SafeOptions} safeOptions
17+
* @param {Info} info
2118
* @returns {string}
2219
*/
23-
export function definition(node, _, context, safeOptions) {
20+
export function definition(node, _, context, info) {
2421
const quote = checkQuote(context)
2522
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
2623
const exit = context.enter('definition')
2724
let subexit = context.enter('label')
28-
const tracker = track(safeOptions)
25+
const tracker = track(info)
2926
let value = tracker.move('[')
3027
value += tracker.move(
3128
safe(context, association(node), {

lib/handle/emphasis.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/**
22
* @typedef {import('mdast').Emphasis} Emphasis
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
*/
107

118
import {checkEmphasis} from '../util/check-emphasis.js'
@@ -20,15 +17,15 @@ emphasis.peek = emphasisPeek
2017
// Do we need to safeguard against that?
2118
/**
2219
* @param {Emphasis} node
23-
* @param {Parent|undefined} _
20+
* @param {Parent | undefined} _
2421
* @param {Context} context
25-
* @param {SafeOptions} safeOptions
22+
* @param {Info} info
2623
* @returns {string}
2724
*/
28-
export function emphasis(node, _, context, safeOptions) {
25+
export function emphasis(node, _, context, info) {
2926
const marker = checkEmphasis(context)
3027
const exit = context.enter('emphasis')
31-
const tracker = track(safeOptions)
28+
const tracker = track(info)
3229
let value = tracker.move(marker)
3330
value += tracker.move(
3431
containerPhrasing(node, context, {
@@ -44,7 +41,7 @@ export function emphasis(node, _, context, safeOptions) {
4441

4542
/**
4643
* @param {Emphasis} _
47-
* @param {Parent|undefined} _1
44+
* @param {Parent | undefined} _1
4845
* @param {Context} context
4946
* @returns {string}
5047
*/

lib/handle/heading.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/**
22
* @typedef {import('mdast').Heading} Heading
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
*/
107

118
import {formatHeadingAsSetext} from '../util/format-heading-as-setext.js'
@@ -14,14 +11,14 @@ import {track} from '../util/track.js'
1411

1512
/**
1613
* @param {Heading} node
17-
* @param {Parent|undefined} _
14+
* @param {Parent | undefined} _
1815
* @param {Context} context
19-
* @param {SafeOptions} safeOptions
16+
* @param {Info} info
2017
* @returns {string}
2118
*/
22-
export function heading(node, _, context, safeOptions) {
19+
export function heading(node, _, context, info) {
2320
const rank = Math.max(Math.min(6, node.depth || 1), 1)
24-
const tracker = track(safeOptions)
21+
const tracker = track(info)
2522

2623
if (formatHeadingAsSetext(node, context)) {
2724
const exit = context.enter('headingSetext')

lib/handle/html.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/**
22
* @typedef {import('mdast').HTML} HTML
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
63
*/
74

85
html.peek = htmlPeek

lib/handle/image-reference.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/**
22
* @typedef {import('mdast').ImageReference} ImageReference
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
*/
107

118
import {association} from '../util/association.js'
@@ -16,16 +13,16 @@ imageReference.peek = imageReferencePeek
1613

1714
/**
1815
* @param {ImageReference} node
19-
* @param {Parent|undefined} _
16+
* @param {Parent | undefined} _
2017
* @param {Context} context
21-
* @param {SafeOptions} safeOptions
18+
* @param {Info} info
2219
* @returns {string}
2320
*/
24-
export function imageReference(node, _, context, safeOptions) {
21+
export function imageReference(node, _, context, info) {
2522
const type = node.referenceType
2623
const exit = context.enter('imageReference')
2724
let subexit = context.enter('label')
28-
const tracker = track(safeOptions)
25+
const tracker = track(info)
2926
let value = tracker.move('![')
3027
const alt = safe(context, node.alt, {
3128
before: value,

lib/handle/image.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/**
22
* @typedef {import('mdast').Image} Image
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
*/
107

118
import {checkQuote} from '../util/check-quote.js'
@@ -16,17 +13,17 @@ image.peek = imagePeek
1613

1714
/**
1815
* @param {Image} node
19-
* @param {Parent|undefined} _
16+
* @param {Parent | undefined} _
2017
* @param {Context} context
21-
* @param {SafeOptions} safeOptions
18+
* @param {Info} info
2219
* @returns {string}
2320
*/
24-
export function image(node, _, context, safeOptions) {
21+
export function image(node, _, context, info) {
2522
const quote = checkQuote(context)
2623
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
2724
const exit = context.enter('image')
2825
let subexit = context.enter('label')
29-
const tracker = track(safeOptions)
26+
const tracker = track(info)
3027
let value = tracker.move('![')
3128
value += tracker.move(
3229
safe(context, node.alt, {before: value, after: ']', ...tracker.current()})

lib/handle/inline-code.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/**
22
* @typedef {import('mdast').InlineCode} InlineCode
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
85
*/
96

@@ -13,7 +10,7 @@ inlineCode.peek = inlineCodePeek
1310

1411
/**
1512
* @param {InlineCode} node
16-
* @param {Parent|undefined} _
13+
* @param {Parent | undefined} _
1714
* @param {Context} context
1815
* @returns {string}
1916
*/
@@ -48,7 +45,7 @@ export function inlineCode(node, _, context) {
4845
while (++index < context.unsafe.length) {
4946
const pattern = context.unsafe[index]
5047
const expression = patternCompile(pattern)
51-
/** @type {RegExpExecArray|null} */
48+
/** @type {RegExpExecArray | null} */
5249
let match
5350

5451
// Only look for `atBreak`s.

lib/handle/link-reference.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/**
22
* @typedef {import('mdast').LinkReference} LinkReference
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
5-
* @typedef {Root|Content} Node
6-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
3+
* @typedef {import('../types.js').Parent} Parent
74
* @typedef {import('../types.js').Context} Context
8-
* @typedef {import('../types.js').SafeOptions} SafeOptions
5+
* @typedef {import('../types.js').Info} Info
96
*/
107

118
import {association} from '../util/association.js'
@@ -17,16 +14,16 @@ linkReference.peek = linkReferencePeek
1714

1815
/**
1916
* @param {LinkReference} node
20-
* @param {Parent|undefined} _
17+
* @param {Parent | undefined} _
2118
* @param {Context} context
22-
* @param {SafeOptions} safeOptions
19+
* @param {Info} info
2320
* @returns {string}
2421
*/
25-
export function linkReference(node, _, context, safeOptions) {
22+
export function linkReference(node, _, context, info) {
2623
const type = node.referenceType
2724
const exit = context.enter('linkReference')
2825
let subexit = context.enter('label')
29-
const tracker = track(safeOptions)
26+
const tracker = track(info)
3027
let value = tracker.move('[')
3128
const text = containerPhrasing(node, context, {
3229
before: value,

0 commit comments

Comments
 (0)