Skip to content

Commit e701470

Browse files
committed
Add one, all helpers to state
In the future, the `one` and `all` exports will be removed. Use the helpers provided on `state` instead.
1 parent 8179548 commit e701470

22 files changed

+185
-195
lines changed

index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export type {State, Handler, Handlers, Options} from './lib/state.js'
1111
export type H = State
1212

1313
// Expose JS API.
14-
export {one, all} from './lib/traverse.js'
1514
export {handlers as defaultHandlers} from './lib/handlers/index.js'
15+
// To do: next major: remove.
16+
export {one, all} from './lib/state.js'
1617
export {toHast} from './lib/index.js'
1718

1819
// Expose node type.

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Note: types exposed from `index.d.ts`.
2-
export {one, all} from './lib/traverse.js'
32
export {handlers as defaultHandlers} from './lib/handlers/index.js'
3+
// To do: next major: remove.
4+
export {one, all} from './lib/state.js'
45
export {toHast} from './lib/index.js'

lib/footer.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import {normalizeUri} from 'micromark-util-sanitize-uri'
9-
import {all} from './traverse.js'
109
import {wrap} from './wrap.js'
1110

1211
/**
@@ -29,7 +28,7 @@ export function footer(state) {
2928
continue
3029
}
3130

32-
const content = all(state, def)
31+
const content = state.all(def)
3332
const id = String(def.identifier)
3433
const safeId = normalizeUri(id.toLowerCase())
3534
let referenceIndex = 0

lib/handlers/blockquote.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import {wrap} from '../wrap.js'
8-
import {all} from '../traverse.js'
98

109
/**
1110
* Turn an mdast `blockquote` node into hast.
@@ -23,7 +22,7 @@ export function blockquote(state, node) {
2322
type: 'element',
2423
tagName: 'blockquote',
2524
properties: {},
26-
children: wrap(all(state, node), true)
25+
children: wrap(state.all(node), true)
2726
}
2827
state.patch(node, result)
2928
return state.applyData(node, result)

lib/handlers/delete.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
66
*/
77

8-
import {all} from '../traverse.js'
9-
108
/**
119
* Turn an mdast `delete` node into hast.
1210
*
@@ -23,7 +21,7 @@ export function strikethrough(state, node) {
2321
type: 'element',
2422
tagName: 'del',
2523
properties: {},
26-
children: all(state, node)
24+
children: state.all(node)
2725
}
2826
state.patch(node, result)
2927
return state.applyData(node, result)

lib/handlers/emphasis.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7-
import {all} from '../traverse.js'
8-
97
/**
108
* Turn an mdast `emphasis` node into hast.
119
*
@@ -22,7 +20,7 @@ export function emphasis(state, node) {
2220
type: 'element',
2321
tagName: 'em',
2422
properties: {},
25-
children: all(state, node)
23+
children: state.all(node)
2624
}
2725
state.patch(node, result)
2826
return state.applyData(node, result)

lib/handlers/heading.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7-
import {all} from '../traverse.js'
8-
97
/**
108
* Turn an mdast `heading` node into hast.
119
*
@@ -22,7 +20,7 @@ export function heading(state, node) {
2220
type: 'element',
2321
tagName: 'h' + node.depth,
2422
properties: {},
25-
children: all(state, node)
23+
children: state.all(node)
2624
}
2725
state.patch(node, result)
2826
return state.applyData(node, result)

lib/handlers/link-reference.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import {normalizeUri} from 'micromark-util-sanitize-uri'
1010
import {revert} from '../revert.js'
11-
import {all} from '../traverse.js'
1211

1312
/**
1413
* Turn an mdast `linkReference` node into hast.
@@ -39,7 +38,7 @@ export function linkReference(state, node) {
3938
type: 'element',
4039
tagName: 'a',
4140
properties,
42-
children: all(state, node)
41+
children: state.all(node)
4342
}
4443
state.patch(node, result)
4544
return state.applyData(node, result)

lib/handlers/link.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import {normalizeUri} from 'micromark-util-sanitize-uri'
9-
import {all} from '../traverse.js'
109

1110
/**
1211
* Turn an mdast `link` node into hast.
@@ -31,7 +30,7 @@ export function link(state, node) {
3130
type: 'element',
3231
tagName: 'a',
3332
properties,
34-
children: all(state, node)
33+
children: state.all(node)
3534
}
3635
state.patch(node, result)
3736
return state.applyData(node, result)

lib/handlers/list-item.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* @typedef {Extract<Nodes, Parent>} Parents
1515
*/
1616

17-
import {all} from '../traverse.js'
18-
1917
/**
2018
* Turn an mdast `listItem` node into hast.
2119
*
@@ -29,7 +27,7 @@ import {all} from '../traverse.js'
2927
* hast node.
3028
*/
3129
export function listItem(state, node, parent) {
32-
const results = all(state, node)
30+
const results = state.all(node)
3331
const loose = parent ? listLoose(parent) : listItemLoose(node)
3432
/** @type {Properties} */
3533
const properties = {}

lib/handlers/list.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import {wrap} from '../wrap.js'
9-
import {all} from '../traverse.js'
109

1110
/**
1211
* Turn an mdast `list` node into hast.
@@ -21,7 +20,7 @@ import {all} from '../traverse.js'
2120
export function list(state, node) {
2221
/** @type {Properties} */
2322
const properties = {}
24-
const results = all(state, node)
23+
const results = state.all(node)
2524
let index = -1
2625

2726
if (typeof node.start === 'number' && node.start !== 1) {

lib/handlers/paragraph.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7-
import {all} from '../traverse.js'
8-
97
/**
108
* Turn an mdast `paragraph` node into hast.
119
*
@@ -22,7 +20,7 @@ export function paragraph(state, node) {
2220
type: 'element',
2321
tagName: 'p',
2422
properties: {},
25-
children: all(state, node)
23+
children: state.all(node)
2624
}
2725
state.patch(node, result)
2826
return state.applyData(node, result)

lib/handlers/root.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* @typedef {import('../state.js').State} State
66
*/
77

8-
import {all} from '../traverse.js'
98
import {wrap} from '../wrap.js'
109

1110
/**
@@ -20,7 +19,7 @@ import {wrap} from '../wrap.js'
2019
*/
2120
export function root(state, node) {
2221
/** @type {HastRoot} */
23-
const result = {type: 'root', children: wrap(all(state, node))}
22+
const result = {type: 'root', children: wrap(state.all(node))}
2423
state.patch(node, result)
2524
return state.applyData(node, result)
2625
}

lib/handlers/strong.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7-
import {all} from '../traverse.js'
8-
97
/**
108
* Turn an mdast `strong` node into hast.
119
*
@@ -22,7 +20,7 @@ export function strong(state, node) {
2220
type: 'element',
2321
tagName: 'strong',
2422
properties: {},
25-
children: all(state, node)
23+
children: state.all(node)
2624
}
2725
state.patch(node, result)
2826
return state.applyData(node, result)

lib/handlers/table-cell.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7-
import {all} from '../traverse.js'
8-
97
/**
108
* Turn an mdast `tableCell` node into hast.
119
*
@@ -24,7 +22,7 @@ export function tableCell(state, node) {
2422
type: 'element',
2523
tagName: 'td', // Assume body cell.
2624
properties: {},
27-
children: all(state, node)
25+
children: state.all(node)
2826
}
2927
state.patch(node, result)
3028
return state.applyData(node, result)

lib/handlers/table-row.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import {wrap} from '../wrap.js'
18-
import {all} from '../traverse.js'
1918

2019
/**
2120
* Turn an mdast `tableRow` node into hast.
@@ -55,7 +54,7 @@ export function tableRow(state, node, parent) {
5554
let result = {type: 'element', tagName, properties, children: []}
5655

5756
if (cell) {
58-
result.children = all(state, cell)
57+
result.children = state.all(cell)
5958
state.patch(cell, result)
6059
result = state.applyData(node, result)
6160
}

lib/handlers/table.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import {pointStart, pointEnd} from 'unist-util-position'
88
import {wrap} from '../wrap.js'
9-
import {all} from '../traverse.js'
109

1110
/**
1211
* Turn an mdast `table` node into hast.
@@ -19,7 +18,7 @@ import {all} from '../traverse.js'
1918
* hast node.
2019
*/
2120
export function table(state, node) {
22-
const rows = all(state, node)
21+
const rows = state.all(node)
2322
const firstRow = rows.shift()
2423
/** @type {Array<Element>} */
2524
const tableContent = []

lib/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* @typedef {MdastRoot | MdastContent} MdastNodes
1414
*/
1515

16-
import {one} from './traverse.js'
1716
import {footer} from './footer.js'
1817
import {createState} from './state.js'
1918

@@ -96,7 +95,7 @@ import {createState} from './state.js'
9695
*/
9796
export function toHast(tree, options) {
9897
const state = createState(tree, options)
99-
const node = one(state, tree, null)
98+
const node = state.one(tree, null)
10099
const foot = footer(state)
101100

102101
if (foot) {

lib/revert.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* @typedef {Extract<Nodes, Reference>} References
1414
*/
1515

16-
import {all} from './traverse.js'
17-
1816
// To do: next major: always return array.
1917

2018
/**
@@ -41,7 +39,7 @@ export function revert(state, node) {
4139
return {type: 'text', value: '![' + node.alt + suffix}
4240
}
4341

44-
const contents = all(state, node)
42+
const contents = state.all(node)
4543
const head = contents[0]
4644

4745
if (head && head.type === 'text') {

0 commit comments

Comments
 (0)