Skip to content

Commit

Permalink
Add one, all helpers to state
Browse files Browse the repository at this point in the history
In the future, the `one` and `all` exports will be removed.
Use the helpers provided on `state` instead.
  • Loading branch information
wooorm committed Feb 3, 2023
1 parent 8179548 commit e701470
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 195 deletions.
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export type {State, Handler, Handlers, Options} from './lib/state.js'
export type H = State

// Expose JS API.
export {one, all} from './lib/traverse.js'
export {handlers as defaultHandlers} from './lib/handlers/index.js'
// To do: next major: remove.
export {one, all} from './lib/state.js'
export {toHast} from './lib/index.js'

// Expose node type.
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Note: types exposed from `index.d.ts`.
export {one, all} from './lib/traverse.js'
export {handlers as defaultHandlers} from './lib/handlers/index.js'
// To do: next major: remove.
export {one, all} from './lib/state.js'
export {toHast} from './lib/index.js'
3 changes: 1 addition & 2 deletions lib/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

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

/**
Expand All @@ -29,7 +28,7 @@ export function footer(state) {
continue
}

const content = all(state, def)
const content = state.all(def)
const id = String(def.identifier)
const safeId = normalizeUri(id.toLowerCase())
let referenceIndex = 0
Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/blockquote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import {wrap} from '../wrap.js'
import {all} from '../traverse.js'

/**
* Turn an mdast `blockquote` node into hast.
Expand All @@ -23,7 +22,7 @@ export function blockquote(state, node) {
type: 'element',
tagName: 'blockquote',
properties: {},
children: wrap(all(state, node), true)
children: wrap(state.all(node), true)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
4 changes: 1 addition & 3 deletions lib/handlers/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/

import {all} from '../traverse.js'

/**
* Turn an mdast `delete` node into hast.
*
Expand All @@ -23,7 +21,7 @@ export function strikethrough(state, node) {
type: 'element',
tagName: 'del',
properties: {},
children: all(state, node)
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
4 changes: 1 addition & 3 deletions lib/handlers/emphasis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @typedef {import('../state.js').State} State
*/

import {all} from '../traverse.js'

/**
* Turn an mdast `emphasis` node into hast.
*
Expand All @@ -22,7 +20,7 @@ export function emphasis(state, node) {
type: 'element',
tagName: 'em',
properties: {},
children: all(state, node)
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
4 changes: 1 addition & 3 deletions lib/handlers/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @typedef {import('../state.js').State} State
*/

import {all} from '../traverse.js'

/**
* Turn an mdast `heading` node into hast.
*
Expand All @@ -22,7 +20,7 @@ export function heading(state, node) {
type: 'element',
tagName: 'h' + node.depth,
properties: {},
children: all(state, node)
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/link-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

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

/**
* Turn an mdast `linkReference` node into hast.
Expand Down Expand Up @@ -39,7 +38,7 @@ export function linkReference(state, node) {
type: 'element',
tagName: 'a',
properties,
children: all(state, node)
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

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

/**
* Turn an mdast `link` node into hast.
Expand All @@ -31,7 +30,7 @@ export function link(state, node) {
type: 'element',
tagName: 'a',
properties,
children: all(state, node)
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
4 changes: 1 addition & 3 deletions lib/handlers/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* @typedef {Extract<Nodes, Parent>} Parents
*/

import {all} from '../traverse.js'

/**
* Turn an mdast `listItem` node into hast.
*
Expand All @@ -29,7 +27,7 @@ import {all} from '../traverse.js'
* hast node.
*/
export function listItem(state, node, parent) {
const results = all(state, node)
const results = state.all(node)
const loose = parent ? listLoose(parent) : listItemLoose(node)
/** @type {Properties} */
const properties = {}
Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import {wrap} from '../wrap.js'
import {all} from '../traverse.js'

/**
* Turn an mdast `list` node into hast.
Expand All @@ -21,7 +20,7 @@ import {all} from '../traverse.js'
export function list(state, node) {
/** @type {Properties} */
const properties = {}
const results = all(state, node)
const results = state.all(node)
let index = -1

if (typeof node.start === 'number' && node.start !== 1) {
Expand Down
4 changes: 1 addition & 3 deletions lib/handlers/paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @typedef {import('../state.js').State} State
*/

import {all} from '../traverse.js'

/**
* Turn an mdast `paragraph` node into hast.
*
Expand All @@ -22,7 +20,7 @@ export function paragraph(state, node) {
type: 'element',
tagName: 'p',
properties: {},
children: all(state, node)
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @typedef {import('../state.js').State} State
*/

import {all} from '../traverse.js'
import {wrap} from '../wrap.js'

/**
Expand All @@ -20,7 +19,7 @@ import {wrap} from '../wrap.js'
*/
export function root(state, node) {
/** @type {HastRoot} */
const result = {type: 'root', children: wrap(all(state, node))}
const result = {type: 'root', children: wrap(state.all(node))}
state.patch(node, result)
return state.applyData(node, result)
}
4 changes: 1 addition & 3 deletions lib/handlers/strong.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @typedef {import('../state.js').State} State
*/

import {all} from '../traverse.js'

/**
* Turn an mdast `strong` node into hast.
*
Expand All @@ -22,7 +20,7 @@ export function strong(state, node) {
type: 'element',
tagName: 'strong',
properties: {},
children: all(state, node)
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
4 changes: 1 addition & 3 deletions lib/handlers/table-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @typedef {import('../state.js').State} State
*/

import {all} from '../traverse.js'

/**
* Turn an mdast `tableCell` node into hast.
*
Expand All @@ -24,7 +22,7 @@ export function tableCell(state, node) {
type: 'element',
tagName: 'td', // Assume body cell.
properties: {},
children: all(state, node)
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/table-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import {wrap} from '../wrap.js'
import {all} from '../traverse.js'

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

if (cell) {
result.children = all(state, cell)
result.children = state.all(cell)
state.patch(cell, result)
result = state.applyData(node, result)
}
Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

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

/**
* Turn an mdast `table` node into hast.
Expand All @@ -19,7 +18,7 @@ import {all} from '../traverse.js'
* hast node.
*/
export function table(state, node) {
const rows = all(state, node)
const rows = state.all(node)
const firstRow = rows.shift()
/** @type {Array<Element>} */
const tableContent = []
Expand Down
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @typedef {MdastRoot | MdastContent} MdastNodes
*/

import {one} from './traverse.js'
import {footer} from './footer.js'
import {createState} from './state.js'

Expand Down Expand Up @@ -96,7 +95,7 @@ import {createState} from './state.js'
*/
export function toHast(tree, options) {
const state = createState(tree, options)
const node = one(state, tree, null)
const node = state.one(tree, null)
const foot = footer(state)

if (foot) {
Expand Down
4 changes: 1 addition & 3 deletions lib/revert.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* @typedef {Extract<Nodes, Reference>} References
*/

import {all} from './traverse.js'

// To do: next major: always return array.

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

const contents = all(state, node)
const contents = state.all(node)
const head = contents[0]

if (head && head.type === 'text') {
Expand Down
Loading

0 comments on commit e701470

Please sign in to comment.