File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1
1
.DS_Store
2
+ * .d.ts
2
3
* .log
3
4
coverage /
4
5
node_modules /
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @typedef {import('unist').Node } Node
3
+ * @typedef {import('unist-util-visit').Visitor<Node> } Visitor
4
+ */
5
+
1
6
import { visit } from 'unist-util-visit'
2
7
3
- // Make an mdast tree compact by merging adjacent text nodes.
8
+ /**
9
+ * Make an mdast tree compact by merging adjacent text nodes.
10
+ *
11
+ * @template {Node} T
12
+ * @param {T } tree
13
+ * @returns {T }
14
+ */
4
15
export function compact ( tree ) {
5
16
visit ( tree , visitor )
6
17
7
18
return tree
8
19
20
+ /** @type {Visitor } */
9
21
function visitor ( child , index , parent ) {
10
22
var siblings = parent ? parent . children : [ ]
11
23
var previous = index && siblings [ index - 1 ]
@@ -16,10 +28,12 @@ export function compact(tree) {
16
28
( child . type === 'text' || child . type === 'blockquote' )
17
29
) {
18
30
if ( child . value ) {
31
+ // @ts -ignore must be text.
19
32
previous . value += child . value
20
33
}
21
34
22
35
if ( child . children ) {
36
+ // @ts -ignore must be block quote.
23
37
previous . children = previous . children . concat ( child . children )
24
38
}
25
39
Original file line number Diff line number Diff line change 26
26
"sideEffects" : false ,
27
27
"type" : " module" ,
28
28
"main" : " index.js" ,
29
+ "types" : " index.d.ts" ,
29
30
"files" : [
31
+ " index.d.ts" ,
30
32
" index.js"
31
33
],
32
34
"dependencies" : {
35
+ "@types/unist" : " ^2.0.0" ,
33
36
"unist-util-visit" : " ^3.0.0"
34
37
},
35
38
"devDependencies" : {
39
+ "@types/tape" : " ^4.0.0" ,
36
40
"c8" : " ^7.0.0" ,
37
41
"prettier" : " ^2.0.0" ,
38
42
"remark-cli" : " ^9.0.0" ,
39
43
"remark-preset-wooorm" : " ^8.0.0" ,
44
+ "rimraf" : " ^3.0.0" ,
40
45
"tape" : " ^5.0.0" ,
46
+ "type-coverage" : " ^2.0.0" ,
47
+ "typescript" : " ^4.0.0" ,
41
48
"unist-builder" : " ^3.0.0" ,
42
49
"xo" : " ^0.39.0"
43
50
},
44
51
"scripts" : {
52
+ "prepack" : " npm run build && npm run format" ,
53
+ "build" : " rimraf \" *.d.ts\" && tsc && type-coverage" ,
45
54
"format" : " remark . -qfo && prettier . -w --loglevel warn && xo --fix" ,
46
55
"test-api" : " node test.js" ,
47
56
"test-coverage" : " c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js" ,
66
75
"plugins" : [
67
76
" preset-wooorm"
68
77
]
78
+ },
79
+ "typeCoverage" : {
80
+ "atLeast" : 100 ,
81
+ "detail" : true ,
82
+ "strict" : true
69
83
}
70
84
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "include" : [" *.js" ],
3
+ "compilerOptions" : {
4
+ "target" : " ES2020" ,
5
+ "lib" : [" ES2020" ],
6
+ "module" : " ES2020" ,
7
+ "moduleResolution" : " node" ,
8
+ "allowJs" : true ,
9
+ "checkJs" : true ,
10
+ "declaration" : true ,
11
+ "emitDeclarationOnly" : true ,
12
+ "allowSyntheticDefaultImports" : true ,
13
+ "skipLibCheck" : true
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments