Skip to content

Commit 84272f7

Browse files
committed
Refactor code-style
1 parent eae5fbd commit 84272f7

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ export function size(tree, test) {
3535

3636
if (children && children.length > 0) {
3737
while (++index < children.length) {
38+
const child = children[index]
3839
// @ts-expect-error Looks like a parent.
39-
if (is(children[index], index, node)) count++
40-
count += fastSize(children[index])
40+
if (is(child, index, node)) count++
41+
count += fastSize(child)
4142
}
4243
}
4344

test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import assert from 'node:assert/strict'
22
import test from 'node:test'
33
import {h} from 'hastscript'
44
import {size} from './index.js'
5-
import * as mod from './index.js'
65

7-
test('size', () => {
8-
assert.deepEqual(
9-
Object.keys(mod).sort(),
10-
['size'],
11-
'should expose the public api'
12-
)
6+
test('size', async function (t) {
7+
await t.test('should expose the public api', async function () {
8+
assert.deepEqual(Object.keys(await import('./index.js')).sort(), ['size'])
9+
})
1310

1411
const tree = h('div', [
1512
h('p', [
@@ -22,13 +19,16 @@ test('size', () => {
2219
h('pre', h('code', 'bar()'))
2320
])
2421

25-
assert.equal(size(tree), 11, 'complete tree')
2622
const p = tree.children[0]
2723
assert(p)
2824
assert(p.type === 'element')
29-
assert.equal(size(p), 7, 'parent node with mixed children')
30-
assert.equal(size(p.children[1]), 1, 'parent of text')
31-
assert.equal(size(p.children[0]), 0, 'text node')
3225

33-
assert.equal(size(tree, 'element'), 5, 'test')
26+
await t.test('should work', async function () {
27+
assert.equal(size(tree), 11)
28+
29+
assert.equal(size(p), 7, 'parent node with mixed children')
30+
assert.equal(size(p.children[1]), 1, 'parent of text')
31+
assert.equal(size(p.children[0]), 0, 'text node')
32+
assert.equal(size(tree, 'element'), 5, 'test')
33+
})
3434
})

0 commit comments

Comments
 (0)