Skip to content

Commit

Permalink
Update @types/hast, utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 6, 2023
1 parent 7a76496 commit 23a91fc
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 94 deletions.
4 changes: 2 additions & 2 deletions lib/handle/comment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('../types.js').Comment} Comment
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Parents} Parents
* @typedef {import('../types.js').State} State
*/

Expand All @@ -13,7 +13,7 @@ import {stringifyEntities} from 'stringify-entities'
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* @param {Parents | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
Expand Down
4 changes: 2 additions & 2 deletions lib/handle/doctype.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('../types.js').DocType} DocType
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Parents} Parents
* @typedef {import('../types.js').State} State
*/

Expand All @@ -11,7 +11,7 @@
* Node to handle.
* @param {number | undefined} _2
* Index of `node` in `parent.
* @param {Parent | undefined} _3
* @param {Parents | undefined} _3
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
Expand Down
6 changes: 4 additions & 2 deletions lib/handle/element.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Parents} Parents
* @typedef {import('../types.js').Element} Element
* @typedef {import('../types.js').Properties} Properties
* @typedef {import('../types.js').PropertyValue} PropertyValue
Expand Down Expand Up @@ -53,7 +53,7 @@ const constants = {
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
Expand Down Expand Up @@ -89,6 +89,8 @@ export function element(node, index, parent, state) {
// categorisation.
// This enables for example `menuitem`s, which are void in W3C HTML but not
// void in WHATWG HTML, to be stringified properly.
// Note: `menuitem` has since been removed from the HTML spec, and so is no
// longer void.
if (content) selfClosing = false

if (attrs || !omit || !opening(node, index, parent)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/handle/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Node} Node
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Nodes} Nodes
* @typedef {import('../types.js').Parents} Parents
*/

import {zwitch} from 'zwitch'
Expand All @@ -13,7 +13,7 @@ import {root} from './root.js'
import {text} from './text.js'

/**
* @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
* @type {(node: Nodes, index: number | undefined, parent: Parents | undefined, state: State) => string}
*/
export const handle = zwitch('type', {
invalid,
Expand Down
4 changes: 2 additions & 2 deletions lib/handle/raw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Parents} Parents
* @typedef {import('../types.js').Raw} Raw
*/

Expand All @@ -13,7 +13,7 @@ import {text} from './text.js'
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
Expand Down
4 changes: 2 additions & 2 deletions lib/handle/root.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('../types.js').Root} Root
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Parents} Parents
* @typedef {import('../types.js').State} State
*/

Expand All @@ -11,7 +11,7 @@
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* @param {Parents | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
Expand Down
4 changes: 2 additions & 2 deletions lib/handle/text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Parents} Parents
* @typedef {import('../types.js').Raw} Raw
* @typedef {import('../types.js').Text} Text
*/
Expand All @@ -14,7 +14,7 @@ import {stringifyEntities} from 'stringify-entities'
* Node to handle.
* @param {number | undefined} _
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
Expand Down
14 changes: 7 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @typedef {import('./types.js').Node} Node
* @typedef {import('./types.js').Parent} Parent
* @typedef {import('./types.js').Content} Content
* @typedef {import('./types.js').Nodes} Nodes
* @typedef {import('./types.js').Parents} Parents
* @typedef {import('./types.js').RootContent} RootContent
* @typedef {import('./types.js').Options} Options
* @typedef {import('./types.js').State} State
*/
Expand All @@ -13,7 +13,7 @@ import {handle} from './handle/index.js'
/**
* Serialize hast as HTML.
*
* @param {Node | Array<Content>} tree
* @param {Nodes | Array<RootContent>} tree
* Tree to serialize.
* @param {Options | null | undefined} [options]
* Configuration.
Expand Down Expand Up @@ -71,11 +71,11 @@ export function toHtml(tree, options) {
*
* @this {State}
* Info passed around about the current state.
* @param {Node} node
* @param {Nodes} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of `node`.
* @returns {string}
* Serialized node.
Expand All @@ -89,7 +89,7 @@ function one(node, index, parent) {
*
* @this {State}
* Info passed around about the current state.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent whose children to serialize.
* @returns {string}
*/
Expand Down
56 changes: 16 additions & 40 deletions lib/omission/closing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('../types.js').Element} Element
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Parents} Parents
*/

import {whitespace} from 'hast-util-whitespace'
Expand All @@ -19,7 +19,6 @@ export const closing = omission({
rp: rubyElement,
optgroup,
option,
menuitem,
colgroup: headOrColgroupOrCaption,
caption: headOrColgroupOrCaption,
thead,
Expand All @@ -37,7 +36,7 @@ export const closing = omission({
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -58,7 +57,7 @@ function headOrColgroupOrCaption(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -75,7 +74,7 @@ function html(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -92,7 +91,7 @@ function body(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand Down Expand Up @@ -153,7 +152,7 @@ function p(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -170,7 +169,7 @@ function li(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -191,7 +190,7 @@ function dt(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -212,7 +211,7 @@ function dd(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -233,7 +232,7 @@ function rubyElement(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -250,7 +249,7 @@ function optgroup(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -264,37 +263,14 @@ function option(_, index, parent) {
)
}

/**
* Whether to omit `</menuitem>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function menuitem(_, index, parent) {
const next = siblingAfter(parent, index)
return (
!next ||
(next.type === 'element' &&
(next.tagName === 'menuitem' ||
next.tagName === 'hr' ||
next.tagName === 'menu'))
)
}

/**
* Whether to omit `</thead>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -315,7 +291,7 @@ function thead(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -336,7 +312,7 @@ function tbody(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -352,7 +328,7 @@ function tfoot(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand All @@ -369,7 +345,7 @@ function tr(_, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
Expand Down
8 changes: 4 additions & 4 deletions lib/omission/opening.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @typedef {import('../types.js').Element} Element
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Content} Content
* @typedef {import('../types.js').Parents} Parents
* @typedef {import('../types.js').RootContent} RootContent
*/

import {whitespace} from 'hast-util-whitespace'
Expand Down Expand Up @@ -94,7 +94,7 @@ function body(node) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the opening tag can be omitted.
Expand Down Expand Up @@ -124,7 +124,7 @@ function colgroup(node, index, parent) {
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* @param {Parents | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the opening tag can be omitted.
Expand Down
Loading

0 comments on commit 23a91fc

Please sign in to comment.