Skip to content

Commit 765021e

Browse files
committed
Replace all export with state.all
1 parent c2fab89 commit 765021e

File tree

19 files changed

+46
-46
lines changed

19 files changed

+46
-46
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
* @typedef {import('./lib/types.js').Options} Options
55
*/
66

7-
export {one, all, defaultHandlers, toMdast} from './lib/index.js'
7+
export {one, defaultHandlers, toMdast} from './lib/index.js'

lib/handlers/a.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
87
import {resolve} from '../util/resolve.js'
98

109
/**
@@ -24,7 +23,7 @@ export function a(state, node) {
2423
url: resolve(state, String(properties.href || '') || null),
2524
title: properties.title ? String(properties.title) : null,
2625
// @ts-expect-error: assume valid children.
27-
children: all(state, node)
26+
children: state.all(node)
2827
}
2928
state.patch(node, result)
3029
return result

lib/handlers/del.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -19,7 +17,7 @@ export function del(state, node) {
1917
const result = {
2018
type: 'delete',
2119
// @ts-expect-error: assume valid children.
22-
children: all(state, node)
20+
children: state.all(node)
2321
}
2422
state.patch(node, result)
2523
return result

lib/handlers/em.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -19,7 +17,7 @@ export function em(state, node) {
1917
const result = {
2018
type: 'emphasis',
2119
// @ts-expect-error: assume valid children.
22-
children: all(state, node)
20+
children: state.all(node)
2321
}
2422
state.patch(node, result)
2523
return result

lib/handlers/heading.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -24,7 +22,7 @@ export function heading(state, node) {
2422
// @ts-expect-error: fine.
2523
depth,
2624
// @ts-expect-error: assume valid children.
27-
children: all(state, node)
25+
children: state.all(node)
2826
}
2927
state.patch(node, result)
3028
return result

lib/handlers/media.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import {toString} from 'mdast-util-to-string'
1010
import {visit, EXIT} from 'unist-util-visit'
11-
import {all} from '../all.js'
1211
import {resolve} from '../util/resolve.js'
1312
import {wrapNeeded} from '../util/wrap.js'
1413

@@ -26,7 +25,7 @@ export function media(state, node) {
2625
let src = String(properties.src || '')
2726
let index = -1
2827
let linkInFallbackContent = false
29-
let nodes = all(state, node)
28+
let nodes = state.all(node)
3029

3130
visit({type: 'root', children: nodes}, 'link', findLink)
3231

lib/handlers/p.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -15,7 +13,7 @@ import {all} from '../all.js'
1513
* mdast node.
1614
*/
1715
export function p(state, node) {
18-
const nodes = all(state, node)
16+
const nodes = state.all(node)
1917

2018
if (nodes.length > 0) {
2119
/** @type {Paragraph} */

lib/handlers/q.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
const defaultQuotes = ['"']
108

119
/**
@@ -20,7 +18,7 @@ export function q(state, node) {
2018
const quotes = state.options.quotes || defaultQuotes
2119

2220
state.qNesting++
23-
const contents = all(state, node)
21+
const contents = state.all(node)
2422
state.qNesting--
2523

2624
const quote = quotes[state.qNesting % quotes.length]

lib/handlers/root.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
87
import {wrap, wrapNeeded} from '../util/wrap.js'
98

109
/**
@@ -16,7 +15,7 @@ import {wrap, wrapNeeded} from '../util/wrap.js'
1615
* mdast node.
1716
*/
1817
export function root(state, node) {
19-
let children = all(state, node)
18+
let children = state.all(node)
2019

2120
if (state.options.document || wrapNeeded(children)) {
2221
// @ts-expect-error: improve `all`?

lib/handlers/strong.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -19,7 +17,7 @@ export function strong(state, node) {
1917
const result = {
2018
type: 'strong',
2119
// @ts-expect-error: assume valid children.
22-
children: all(state, node)
20+
children: state.all(node)
2321
}
2422
state.patch(node, result)
2523
return result

lib/handlers/table-cell.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -15,7 +13,7 @@ import {all} from '../all.js'
1513
* mdast node.
1614
*/
1715
export function tableCell(state, node) {
18-
const children = all(state, node)
16+
const children = state.all(node)
1917

2018
/** @type {TableCell} */
2119
const result = {

lib/handlers/table-row.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -19,7 +17,7 @@ export function tableRow(state, node) {
1917
const result = {
2018
type: 'tableRow',
2119
// @ts-expect-error: assume valid children.
22-
children: all(state, node)
20+
children: state.all(node)
2321
}
2422
state.patch(node, result)
2523
return result

lib/handlers/table.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import {toText} from 'hast-util-to-text'
2121
import {visit, SKIP} from 'unist-util-visit'
22-
import {all} from '../all.js'
2322

2423
/**
2524
* @param {State} state
@@ -42,7 +41,7 @@ export function table(state, node) {
4241
state.inTable = true
4342

4443
const {headless, align} = inspect(node)
45-
const rows = toRows(all(state, node), headless)
44+
const rows = toRows(state.all(node), headless)
4645
let columns = 1
4746
let rowIndex = -1
4847

lib/index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010

1111
/**
1212
* @typedef {Root | Content} Node
13+
* @typedef {Extract<Node, import('unist').Parent>} Parent
1314
* @typedef {MdastRoot | MdastContent} MdastNode
1415
*/
1516

1617
import rehypeMinifyWhitespace from 'rehype-minify-whitespace'
1718
import {position} from 'unist-util-position'
1819
import {visit} from 'unist-util-visit'
19-
import {one} from './one.js'
2020
import {handlers} from './handlers/index.js'
21+
import {one} from './one.js'
22+
import {all} from './all.js'
2123

2224
export {one} from './one.js'
23-
export {all} from './all.js'
2425

2526
/**
2627
* Transform hast to mdast.
@@ -39,6 +40,7 @@ export function toMdast(tree, options) {
3940
/** @type {State} */
4041
const state = {
4142
patch,
43+
all: allBound,
4244
options: options_,
4345
nodeById: byId,
4446
handlers: options_.handlers
@@ -152,3 +154,17 @@ export {handlers as defaultHandlers} from './handlers/index.js'
152154
function patch(origin, node) {
153155
if (origin.position) node.position = position(origin)
154156
}
157+
158+
/**
159+
* Transform the children of a hast parent to mdast.
160+
*
161+
* @this {State}
162+
* Info passed around about the current state.
163+
* @param {Parent} parent
164+
* Parent.
165+
* @returns {Array<MdastContent>}
166+
* mdast children.
167+
*/
168+
function allBound(parent) {
169+
return all(this, parent)
170+
}

lib/one.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* @typedef {MdastRoot | MdastContent} MdastNode
1414
*/
1515

16-
import {all} from './all.js'
17-
1816
export const own = {}.hasOwnProperty
1917

2018
/**
@@ -67,6 +65,6 @@ function unknown(state, node) {
6765
}
6866

6967
if ('children' in node) {
70-
return all(state, node)
68+
return state.all(node)
7169
}
7270
}

lib/types.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
*
5454
* @typedef State
5555
* Info passed around about the current state.
56+
* @property {PatchPosition} patch
57+
* Copy a node’s positional info.
58+
* @property {All} all
59+
* Transform the children of a hast parent to mdast.
5660
* @property {Options} options
5761
* User configuration.
5862
* @property {Record<string, Element>} nodeById
@@ -67,7 +71,6 @@
6771
* Whether we’re in a table.
6872
* @property {number} qNesting
6973
* Non-negative finite integer representing how deep we’re in `<q>`s.
70-
* @property {PatchPosition} patch
7174
*
7275
* @callback PatchPosition
7376
* Copy a node’s positional info.
@@ -77,6 +80,13 @@
7780
* mdast node to copy into.
7881
* @returns {void}
7982
* Nothing.
83+
*
84+
* @callback All
85+
* Transform the children of a hast parent to mdast.
86+
* @param {Parent} parent
87+
* Parent.
88+
* @returns {Array<MdastContent>}
89+
* mdast children.
8090
*/
8191

8292
export {}

lib/util/wrap-children.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
87
import {wrap} from './wrap.js'
98

109
/**
@@ -17,5 +16,5 @@ import {wrap} from './wrap.js'
1716
*/
1817
export function wrapChildren(state, node) {
1918
// @ts-expect-error: improve `all`?
20-
return wrap(all(state, node))
19+
return wrap(state.all(node))
2120
}

lib/util/wrap-list-items.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {all} from '../all.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -15,7 +13,7 @@ import {all} from '../all.js'
1513
* List items.
1614
*/
1715
export function wrapListItems(state, node) {
18-
const nodes = all(state, node)
16+
const nodes = state.all(node)
1917
/** @type {Array<ListContent>} */
2018
const results = []
2119
let index = -1

test/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {toMarkdown} from 'mdast-util-to-markdown'
1515
import {gfm} from 'micromark-extension-gfm'
1616
import {u} from 'unist-builder'
1717
import {removePosition} from 'unist-util-remove-position'
18-
import {one, all, defaultHandlers, toMdast} from '../index.js'
18+
import {one, defaultHandlers, toMdast} from '../index.js'
1919
import {wrapNeeded} from '../lib/util/wrap.js'
2020

2121
test('custom nodes', (t) => {
@@ -46,7 +46,6 @@ test('custom nodes', (t) => {
4646

4747
test('exports', (t) => {
4848
t.ok(one, 'should export `one`')
49-
t.ok(all, 'should export `all`')
5049
t.ok(defaultHandlers, 'should export `defaultHandlers`')
5150
t.end()
5251
})

0 commit comments

Comments
 (0)