Skip to content

Commit 000c4fe

Browse files
committed
Change to remove support for non-nodes
1 parent 307fe26 commit 000c4fe

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

lib/index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/**
2-
* @typedef {import('hast').Root} Root
3-
* @typedef {import('hast').Content} Content
4-
*/
5-
6-
/**
7-
* @typedef {Root | Content} Node
2+
* @typedef {import('hast').Nodes} Nodes
83
*/
94

105
import {hasProperty} from 'hast-util-has-property'
@@ -24,7 +19,7 @@ const alwaysInteractive = new Set([
2419
/**
2520
* Check if the given value is *interactive content*.
2621
*
27-
* @param {Node} node
22+
* @param {Nodes} node
2823
* Node to check.
2924
* @returns {boolean}
3025
* Whether `node` is an `Element` that is classified as *interactive
@@ -41,7 +36,7 @@ const alwaysInteractive = new Set([
4136
* `select`, and `textarea`
4237
*/
4338
export function interactive(node) {
44-
if (!node || typeof node !== 'object' || node.type !== 'element') {
39+
if (node.type !== 'element') {
4540
return false
4641
}
4742

@@ -53,7 +48,7 @@ export function interactive(node) {
5348
(name === 'video' && hasProperty(node, 'controls')) ||
5449
(name === 'object' && hasProperty(node, 'useMap')) ||
5550
(name === 'img' && hasProperty(node, 'useMap')) ||
56-
(name === 'input' && (node.properties || {}).type !== 'hidden') ||
51+
(name === 'input' && node.properties.type !== 'hidden') ||
5752
hasProperty(node, 'tabIndex') ||
5853
alwaysInteractive.has(name)
5954
)

test.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,12 @@ test('interactive', () => {
1010
'should expose the public api'
1111
)
1212

13-
// @ts-expect-error runtime.
14-
assert.equal(interactive(), false, 'should return `false` without node')
15-
// @ts-expect-error runtime.
16-
assert.equal(interactive(null), false, 'should return `false` with `null`')
17-
1813
assert.equal(
1914
interactive({type: 'text', value: 'alpha'}),
2015
false,
2116
'should return `false` without `element`'
2217
)
2318

24-
assert.equal(
25-
// @ts-expect-error: partial.
26-
interactive({type: 'element'}),
27-
false,
28-
'should return `false` without `tagName`'
29-
)
30-
3119
assert.equal(
3220
interactive({
3321
type: 'element',
@@ -236,6 +224,7 @@ test('interactive', () => {
236224
interactive({
237225
type: 'element',
238226
tagName: 'input',
227+
properties: {},
239228
children: []
240229
}),
241230
true,

0 commit comments

Comments
 (0)