Skip to content

Commit 42fe278

Browse files
committed
Update unist-util-visit
1 parent f662588 commit 42fe278

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

lib/handlers/media.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export function media(h, node) {
3232
/** @type {ElementChild} */
3333
let child
3434

35-
// @ts-expect-error: assume valid content.
3635
visit({type: 'root', children: nodes}, 'link', findLink)
3736

3837
// If the content links to something, or if it’s not phrasing…

lib/handlers/table.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,10 @@ function inspect(node) {
4141
/** @type {Array.<string|null>} */
4242
const align = [null]
4343

44-
visit(node, 'element', visitor)
45-
46-
return {align, headless}
47-
48-
/** @type {import('unist-util-visit').Visitor<Element>} */
49-
function visitor(child) {
44+
visit(node, 'element', (child) => {
5045
// If there is a `thead`, assume there is a header row.
51-
if (cell(child)) {
46+
if (cell(child) && child.properties) {
5247
if (!align[cellIndex]) {
53-
// @ts-expect-error: `props` are defined.
5448
align[cellIndex] = String(child.properties.align || '') || null
5549
}
5650

@@ -66,7 +60,9 @@ function inspect(node) {
6660
rowIndex++
6761
cellIndex = 0
6862
}
69-
}
63+
})
64+
65+
return {align, headless}
7066
}
7167

7268
/**

lib/index.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @typedef {import('./types.js').MdastRoot} MdastRoot
1313
*/
1414

15-
import {hasProperty} from 'hast-util-has-property'
1615
// @ts-expect-error: next.
1716
import minifyWhitespace from 'rehype-minify-whitespace'
1817
import {convert} from 'unist-util-is'
@@ -97,7 +96,16 @@ export function toMdast(tree, options = {}) {
9796
}
9897
)
9998

100-
visit(tree, 'element', onelement)
99+
visit(tree, 'element', (node) => {
100+
const id =
101+
node.properties &&
102+
'id' in node.properties &&
103+
String(node.properties.id).toUpperCase()
104+
105+
if (id && !own.call(byId, id)) {
106+
byId[id] = node
107+
}
108+
})
101109

102110
minifyWhitespace({newlines: options.newlines === true})(tree)
103111

@@ -115,17 +123,6 @@ export function toMdast(tree, options = {}) {
115123

116124
return mdast
117125

118-
/** @type {import('unist-util-visit').Visitor<Element>} */
119-
function onelement(node) {
120-
const id =
121-
// @ts-expect-error: `hasProperty` just checked it.
122-
hasProperty(node, 'id') && String(node.properties.id).toUpperCase()
123-
124-
if (id && !own.call(byId, id)) {
125-
byId[id] = node
126-
}
127-
}
128-
129126
/**
130127
* Collapse text nodes, and fix whitespace.
131128
* Most of this is taken care of by `rehype-minify-whitespace`, but

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"repeat-string": "^1.0.0",
5151
"trim-trailing-lines": "^2.0.0",
5252
"unist-util-is": "^5.0.0",
53-
"unist-util-visit": "^3.0.0"
53+
"unist-util-visit": "^4.0.0"
5454
},
5555
"devDependencies": {
5656
"@types/tape": "^4.0.0",

0 commit comments

Comments
 (0)