File tree 3 files changed +13
-19
lines changed
3 files changed +13
-19
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * @typedef {import('mdast').Root } Root
3
- * @typedef {import('mdast').Content } Content
2
+ * @typedef {import('mdast').Nodes } Nodes
4
3
* @typedef {import('mdast').Paragraph } Paragraph
5
4
*/
6
5
7
- /**
8
- * @typedef {Content | Root } Node
9
- */
10
-
11
6
import { visit } from 'unist-util-visit'
12
7
13
8
/**
14
9
* Remove empty paragraphs in `tree`.
15
10
*
16
- * @template {Node } Tree
11
+ * @template {Nodes } Tree
17
12
* Node type.
18
13
* @param {Tree } tree
19
14
* Tree to change.
@@ -27,7 +22,7 @@ export function squeezeParagraphs(tree) {
27
22
}
28
23
29
24
visit ( tree , function ( node , index , parent ) {
30
- if ( index !== null && parent && emptyParagraph ( node ) ) {
25
+ if ( index !== undefined && parent && emptyParagraph ( node ) ) {
31
26
parent . children . splice ( index , 1 )
32
27
return index
33
28
}
@@ -40,7 +35,7 @@ export function squeezeParagraphs(tree) {
40
35
/**
41
36
* Check if a node is an empty paragraph.
42
37
*
43
- * @param {Node } node
38
+ * @param {Nodes } node
44
39
* Node to check.
45
40
* @returns {boolean }
46
41
* Whether `node` was an empty paragraph.
Original file line number Diff line number Diff line change 40
40
" index.js"
41
41
],
42
42
"dependencies" : {
43
- "@types/mdast" : " ^3 .0.0" ,
44
- "unist-util-visit" : " ^4 .0.0"
43
+ "@types/mdast" : " ^4 .0.0" ,
44
+ "unist-util-visit" : " ^5 .0.0"
45
45
},
46
46
"devDependencies" : {
47
- "@types/tape " : " ^5 .0.0" ,
47
+ "@types/node " : " ^20 .0.0" ,
48
48
"c8" : " ^8.0.0" ,
49
49
"prettier" : " ^2.0.0" ,
50
50
"remark-cli" : " ^11.0.0" ,
53
53
"tsd" : " ^0.28.0" ,
54
54
"type-coverage" : " ^2.0.0" ,
55
55
"typescript" : " ^5.0.0" ,
56
- "unist-builder" : " ^3 .0.0" ,
56
+ "unist-builder" : " ^4 .0.0" ,
57
57
"xo" : " ^0.54.0"
58
58
},
59
59
"scripts" : {
Original file line number Diff line number Diff line change 3
3
* @typedef {import('mdast').Paragraph } Paragraph
4
4
*/
5
5
6
- import test from 'tape'
6
+ import assert from 'node:assert/strict'
7
+ import test from 'node:test'
7
8
import { u } from 'unist-builder'
8
9
import { squeezeParagraphs } from './index.js'
9
10
10
- test ( ( t ) => {
11
- t . deepEqual (
11
+ test ( 'squeezeParagraphs' , ( ) => {
12
+ assert . deepEqual (
12
13
squeezeParagraphs (
13
14
/** @type {Root } */ (
14
15
u ( 'root' , [
@@ -41,11 +42,9 @@ test((t) => {
41
42
] )
42
43
)
43
44
44
- t . deepEqual (
45
+ assert . deepEqual (
45
46
squeezeParagraphs ( /** @type {Paragraph } */ ( u ( 'paragraph' , [ ] ) ) ) ,
46
47
null ,
47
48
'should return `null` for empty paragraphs'
48
49
)
49
-
50
- t . end ( )
51
50
} )
You can’t perform that action at this time.
0 commit comments