Skip to content

Commit 6e1ae19

Browse files
committed
Refactor code-style
1 parent bba4b03 commit 6e1ae19

15 files changed

+81
-83
lines changed

lib/all.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
22
* @typedef {import('./types.js').H} H
33
* @typedef {import('./types.js').Node} Node
4-
* @typedef {import('./types.js').Parent} Parent
5-
* @typedef {import('./types.js').Handle} Handle
64
* @typedef {import('./types.js').MdastNode} MdastNode
75
*/
86

@@ -11,13 +9,13 @@ import {one} from './one.js'
119
/**
1210
* @param {H} h
1311
* @param {Node} parent
14-
* @returns {Array.<MdastNode>}
12+
* @returns {Array<MdastNode>}
1513
*/
1614
export function all(h, parent) {
17-
/** @type {Array.<Node>} */
15+
/** @type {Array<Node>} */
1816
// @ts-expect-error Assume `parent` is a parent.
1917
const nodes = parent.children || []
20-
/** @type {Array.<MdastNode>} */
18+
/** @type {Array<MdastNode>} */
2119
const values = []
2220
let index = -1
2321
let length = nodes.length

lib/handlers/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const isCode = convertElement('code')
2121
export function code(h, node) {
2222
const children = node.children
2323
let index = -1
24-
/** @type {Array.<string|number>|undefined} */
24+
/** @type {Array<string|number>|undefined} */
2525
let classList
2626
/** @type {string|undefined} */
2727
let lang

lib/handlers/dl.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* @typedef {import('../types.js').MdastDefinitionContent} MdastDefinitionContent
1010
*
1111
* @typedef Group
12-
* @property {Array.<Element>} titles
13-
* @property {Array.<ElementChild>} definitions
12+
* @property {Array<Element>} titles
13+
* @property {Array<ElementChild>} definitions
1414
*/
1515

1616
import {convertElement} from 'hast-util-is-element'
@@ -28,15 +28,15 @@ const dd = convertElement('dd')
2828
export function dl(h, node) {
2929
const children = node.children
3030
let index = -1
31-
/** @type {Array.<ElementChild>} */
31+
/** @type {Array<ElementChild>} */
3232
let clean = []
33-
/** @type {Array.<Group>} */
33+
/** @type {Array<Group>} */
3434
const groups = []
3535
/** @type {Group} */
3636
let group = {titles: [], definitions: []}
3737
/** @type {ElementChild} */
3838
let child
39-
/** @type {Array.<MdastBlockContent|MdastDefinitionContent>} */
39+
/** @type {Array<MdastBlockContent|MdastDefinitionContent>} */
4040
let result
4141

4242
// Unwrap `<div>`s
@@ -67,7 +67,7 @@ export function dl(h, node) {
6767

6868
// Create items.
6969
index = -1
70-
/** @type {Array.<MdastListContent>} */
70+
/** @type {Array<MdastListContent>} */
7171
const content = []
7272

7373
while (++index < groups.length) {
@@ -99,8 +99,8 @@ export function dl(h, node) {
9999

100100
/**
101101
* @param {H} h
102-
* @param {Array.<ElementChild>} children
103-
* @returns {Array.<MdastBlockContent|MdastDefinitionContent>}
102+
* @param {Array<ElementChild>} children
103+
* @returns {Array<MdastBlockContent|MdastDefinitionContent>}
104104
*/
105105
function handle(h, children) {
106106
const nodes = wrapListItems(h, {type: 'element', tagName: 'x', children})

lib/handlers/input.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export function input(h, node) {
2323
// @ts-expect-error: `props` are defined.
2424
const props = node.properties
2525
let value = String(props.value || props.placeholder || '')
26-
/** @type {Array.<MdastNode>} */
26+
/** @type {Array<MdastNode>} */
2727
const results = []
28-
/** @type {Array.<string>} */
28+
/** @type {Array<string>} */
2929
const texts = []
30-
/** @type {Array.<[string, string|null]>} */
30+
/** @type {Array<[string, string|null]>} */
3131
let values = []
3232
let index = -1
3333
/** @type {string} */

lib/handlers/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {wrapText} from '../util/wrap-text.js'
1313
export function select(h, node) {
1414
const values = findSelectedOptions(h, node)
1515
let index = -1
16-
/** @type {Array.<string>} */
16+
/** @type {Array<string>} */
1717
const results = []
1818
/** @type {[string, string|null]} */
1919
let value

lib/handlers/table.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @typedef {import('../types.js').MdastPhrasingContent} MdastPhrasingContent
88
*
99
* @typedef Info
10-
* @property {Array.<string|null>} align
10+
* @property {Array<string|null>} align
1111
* @property {boolean} headless
1212
*/
1313

@@ -61,7 +61,7 @@ export function table(h, node) {
6161
break
6262
}
6363

64-
/** @type {Array.<MdastRowContent>} */
64+
/** @type {Array<MdastRowContent>} */
6565
const newCells = []
6666

6767
if (otherRowIndex !== rowIndex || colIndex !== cellIndex) {
@@ -114,7 +114,7 @@ function inspect(node) {
114114
let headless = true
115115
let rowIndex = 0
116116
let cellIndex = 0
117-
/** @type {Array.<string|null>} */
117+
/** @type {Array<string|null>} */
118118
const align = [null]
119119

120120
visit(node, 'element', (child) => {
@@ -148,15 +148,15 @@ function inspect(node) {
148148
/**
149149
* Ensure the rows are properly structured.
150150
*
151-
* @param {Array.<MdastNode>} children
151+
* @param {Array<MdastNode>} children
152152
* @param {boolean} headless
153-
* @returns {Array.<MdastTableContent>}
153+
* @returns {Array<MdastTableContent>}
154154
*/
155155
function toRows(children, headless) {
156156
let index = -1
157-
/** @type {Array.<MdastTableContent>} */
157+
/** @type {Array<MdastTableContent>} */
158158
const nodes = []
159-
/** @type {Array.<MdastRowContent>|undefined} */
159+
/** @type {Array<MdastRowContent>|undefined} */
160160
let queue
161161

162162
// Add an empty header row.
@@ -197,16 +197,16 @@ function toRows(children, headless) {
197197
/**
198198
* Ensure the cells in a row are properly structured.
199199
*
200-
* @param {Array.<MdastNode>} children
201-
* @returns {Array.<MdastRowContent>}
200+
* @param {Array<MdastNode>} children
201+
* @returns {Array<MdastRowContent>}
202202
*/
203203
function toCells(children) {
204-
/** @type {Array.<MdastRowContent>} */
204+
/** @type {Array<MdastRowContent>} */
205205
const nodes = []
206206
let index = -1
207207
/** @type {MdastNode} */
208208
let node
209-
/** @type {Array.<MdastPhrasingContent>|undefined} */
209+
/** @type {Array<MdastPhrasingContent>|undefined} */
210210
let queue
211211

212212
while (++index < children.length) {

lib/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
22
* @typedef {import('./types.js').Node} Node
33
* @typedef {import('./types.js').Element} Element
4-
* @typedef {import('./types.js').Text} Text
54
* @typedef {import('./types.js').Options} Options
6-
* @typedef {import('./types.js').Context} Context
75
* @typedef {import('./types.js').Properties} Properties
86
* @typedef {import('./types.js').H} H
97
* @typedef {import('./types.js').HWithoutProps} HWithoutProps
@@ -29,7 +27,7 @@ const block = convert(['heading', 'paragraph', 'root'])
2927
* @param {Options} [options]
3028
*/
3129
export function toMdast(tree, options = {}) {
32-
/** @type {Object.<string, Element>} */
30+
/** @type {Record<string, Element>} */
3331
const byId = {}
3432
/** @type {MdastNode|MdastRoot} */
3533
let mdast
@@ -45,8 +43,8 @@ export function toMdast(tree, options = {}) {
4543
/**
4644
* @param {Node} node
4745
* @param {string} type
48-
* @param {Properties|string|Array.<Node>} [props]
49-
* @param {string|Array.<Node>} [children]
46+
* @param {Properties|string|Array<Node>} [props]
47+
* @param {string|Array<Node>} [children]
5048
*/
5149
(node, type, props, children) => {
5250
/** @type {Properties|undefined} */

lib/one.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {wrapText} from './util/wrap-text.js'
1414
* @param {H} h
1515
* @param {Node} node
1616
* @param {Parent|undefined} parent
17-
* @returns {MdastNode|Array.<MdastNode>|void}
17+
* @returns {MdastNode|Array<MdastNode>|void}
1818
*/
1919
export function one(h, node, parent) {
2020
/** @type {Handle|undefined} */

lib/types.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@
2020
* @typedef {Parent['children'][number]} Child
2121
* @typedef {Child|Root} Node
2222
*
23-
* @typedef {(h: H, node: any, parent?: Parent) => MdastNode|Array.<MdastNode>|void} Handle
23+
* @typedef {(h: H, node: any, parent?: Parent) => MdastNode|Array<MdastNode>|void} Handle
2424
*
2525
* @typedef {Record<string, unknown>} Properties
2626
*
2727
* @typedef Options
28-
* @property {Object.<string, Handle>} [handlers]
28+
* @property {Record<string, Handle>} [handlers]
2929
* @property {boolean} [document]
3030
* @property {boolean} [newlines=false]
3131
* @property {string} [checked='[x]']
3232
* @property {string} [unchecked='[ ]']
33-
* @property {Array.<string>} [quotes=['"']]
33+
* @property {Array<string>} [quotes=['"']]
3434
*
3535
* @typedef Context
36-
* @property {Object.<string, Element>} nodeById
36+
* @property {Record<string, Element>} nodeById
3737
* @property {boolean} baseFound
3838
* @property {string|null} frozenBaseUrl
3939
* @property {boolean} wrapText
4040
* @property {boolean} inTable
4141
* @property {number} qNesting
42-
* @property {Object.<string, Handle>} handlers
42+
* @property {Record<string, Handle>} handlers
4343
* @property {boolean|undefined} document
4444
* @property {string} checked
4545
* @property {string} unchecked
46-
* @property {Array.<string>} quotes
46+
* @property {Array<string>} quotes
4747
*
48-
* @typedef {(node: Node, type: string, props?: Properties, children?: string|Array.<MdastNode>) => MdastNode} HWithProps
49-
* @typedef {(node: Node, type: string, children?: string|Array.<MdastNode>) => MdastNode} HWithoutProps
48+
* @typedef {(node: Node, type: string, props?: Properties, children?: string|Array<MdastNode>) => MdastNode} HWithProps
49+
* @typedef {(node: Node, type: string, children?: string|Array<MdastNode>) => MdastNode} HWithoutProps
5050
*
5151
* @typedef {HWithProps & HWithoutProps & Context} H
5252
*/

lib/util/find-selected-options.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const option = convertElement('option')
1717
* @param {H} h
1818
* @param {Element} node
1919
* @param {Properties} [properties]
20-
* @returns {Array.<[string, string|null]>}
20+
* @returns {Array<[string, string|null]>}
2121
*/
2222
export function findSelectedOptions(h, node, properties) {
2323
/** @type {Properties} */
@@ -28,9 +28,9 @@ export function findSelectedOptions(h, node, properties) {
2828
Math.min(Number.parseInt(String(props.size), 10), 0) ||
2929
(props.multiple ? 4 : 1)
3030
let index = -1
31-
/** @type {Array.<Element>} */
31+
/** @type {Array<Element>} */
3232
const selectedOptions = []
33-
/** @type {Array.<[string, string|null]>} */
33+
/** @type {Array<[string, string|null]>} */
3434
const values = []
3535

3636
while (++index < options.length) {
@@ -63,7 +63,7 @@ export function findSelectedOptions(h, node, properties) {
6363
function findOptions(node) {
6464
const children = node.children
6565
let index = -1
66-
/** @type {Array.<Element>} */
66+
/** @type {Array<Element>} */
6767
let results = []
6868
/** @type {Child} */
6969
let child

lib/util/list-items-spread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
/**
6-
* @param {Array.<MdastListContent>} children
6+
* @param {Array<MdastListContent>} children
77
* @returns {boolean}
88
*/
99
export function listItemsSpread(children) {

lib/util/wrap-children.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {wrap} from './wrap.js'
1010
/**
1111
* @param {H} h
1212
* @param {Node} node
13-
* @returns {Array.<MdastNode>}
13+
* @returns {Array<MdastNode>}
1414
*/
1515
export function wrapChildren(h, node) {
1616
return wrap(all(h, node))

lib/util/wrap-list-items.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* @typedef {import('../types.js').H} H
3-
* @typedef {import('../types.js').Element} Element
43
* @typedef {import('../types.js').Child} Child
54
* @typedef {import('../types.js').MdastListContent} MdastListContent
65
*/
@@ -10,7 +9,7 @@ import {all} from '../all.js'
109
/**
1110
* @param {H} h
1211
* @param {Child} node
13-
* @returns {Array.<MdastListContent>}
12+
* @returns {Array<MdastListContent>}
1413
*/
1514
export function wrapListItems(h, node) {
1615
const children = all(h, node)

0 commit comments

Comments
 (0)