2
2
* @typedef {import('unist').Node } Node
3
3
* @typedef {import('unist').Literal<string> } Literal
4
4
* @typedef {import('mdast').Root } Root
5
+ * @typedef {import('mdast').Text } Text
5
6
* @typedef {import('mdast').InlineCode } InlineCode
6
7
* @typedef {import('vfile').VFile } VFile
7
8
*/
@@ -25,7 +26,7 @@ import {toNlcst} from '../index.js'
25
26
test ( 'mdast-util-to-nlcst' , ( t ) => {
26
27
t . throws (
27
28
( ) => {
28
- // @ts -expect-error runtime.
29
+ // @ts -expect-error runtime: too few arguments .
29
30
toNlcst ( )
30
31
} ,
31
32
/ m d a s t - u t i l - t o - n l c s t e x p e c t e d n o d e / ,
@@ -34,7 +35,7 @@ test('mdast-util-to-nlcst', (t) => {
34
35
35
36
t . throws (
36
37
( ) => {
37
- // @ts -expect-error runtime.
38
+ // @ts -expect-error runtime: too few arguments .
38
39
toNlcst ( { } )
39
40
} ,
40
41
/ m d a s t - u t i l - t o - n l c s t e x p e c t e d n o d e / ,
@@ -43,7 +44,7 @@ test('mdast-util-to-nlcst', (t) => {
43
44
44
45
t . throws (
45
46
( ) => {
46
- // @ts -expect-error runtime.
47
+ // @ts -expect-error runtime: too few arguments .
47
48
toNlcst ( { type : 'foo' } )
48
49
} ,
49
50
/ m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ,
@@ -52,7 +53,7 @@ test('mdast-util-to-nlcst', (t) => {
52
53
53
54
t . throws (
54
55
( ) => {
55
- // @ts -expect-error runtime.
56
+ // @ts -expect-error runtime: too few arguments .
56
57
toNlcst ( { type : 'foo' } )
57
58
} ,
58
59
/ m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ,
@@ -61,7 +62,7 @@ test('mdast-util-to-nlcst', (t) => {
61
62
62
63
t . throws (
63
64
( ) => {
64
- // @ts -expect-error runtime.
65
+ // @ts -expect-error runtime: too few arguments .
65
66
toNlcst ( { type : 'text' , value : 'foo' } , { foo : 'bar' } )
66
67
} ,
67
68
/ m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ,
@@ -70,9 +71,9 @@ test('mdast-util-to-nlcst', (t) => {
70
71
71
72
t . throws (
72
73
( ) => {
73
- // @ts -expect-error runtime.
74
+ // @ts -expect-error runtime: too few arguments .
74
75
toNlcst (
75
- /** @type {Literal } */ ( { type : 'text' , value : 'foo' } ) ,
76
+ /** @type {Text } */ ( { type : 'text' , value : 'foo' } ) ,
76
77
vfile ( { contents : 'foo' } )
77
78
)
78
79
} ,
@@ -83,7 +84,7 @@ test('mdast-util-to-nlcst', (t) => {
83
84
t . throws (
84
85
( ) => {
85
86
toNlcst (
86
- /** @type {Literal } */ ( { type : 'text' , value : 'foo' } ) ,
87
+ /** @type {Text } */ ( { type : 'text' , value : 'foo' } ) ,
87
88
vfile ( ) ,
88
89
ParseLatin
89
90
)
@@ -94,7 +95,7 @@ test('mdast-util-to-nlcst', (t) => {
94
95
95
96
t . doesNotThrow ( ( ) => {
96
97
toNlcst (
97
- /** @type {Literal } */ ( {
98
+ /** @type {Text } */ ( {
98
99
type : 'text' ,
99
100
value : 'foo' ,
100
101
position : { start : { line : 1 , column : 1 } , end : { line : 1 , column : 4 } }
@@ -106,7 +107,7 @@ test('mdast-util-to-nlcst', (t) => {
106
107
107
108
t . doesNotThrow ( ( ) => {
108
109
toNlcst (
109
- /** @type {Literal } */ ( {
110
+ /** @type {Text } */ ( {
110
111
type : 'text' ,
111
112
value : 'foo' ,
112
113
position : { start : { line : 1 , column : 1 } , end : { line : 1 , column : 4 } }
@@ -122,7 +123,7 @@ test('mdast-util-to-nlcst', (t) => {
122
123
{
123
124
type : 'text' ,
124
125
value : 'foo' ,
125
- // @ts -expect-error runtime.
126
+ // @ts -expect-error runtime: incorrect positional info .
126
127
position : { start : { } , end : { } }
127
128
} ,
128
129
vfile ( ) ,
@@ -225,40 +226,30 @@ test('Fixtures', (t) => {
225
226
const base = path . join ( 'test' , 'fixtures' )
226
227
const files = fs . readdirSync ( base )
227
228
let index = - 1
228
- /** @type {string } */
229
- let name
230
- /** @type {VFile } */
231
- let input
232
- /** @type {Node } */
233
- let expected
234
- /** @type {Node } */
235
- let mdast
236
- /** @type {Object.<string, unknown>|undefined } */
237
- let options
238
229
239
230
while ( ++ index < files . length ) {
240
- name = files [ index ]
231
+ const name = files [ index ]
232
+ /** @type {Object.<string, unknown>|undefined } */
233
+ let options
241
234
242
235
if ( isHidden ( name ) ) continue
243
236
244
- input = vfile . readSync ( path . join ( base , name , 'input.md' ) )
245
- expected = JSON . parse (
237
+ const input = vfile . readSync ( path . join ( base , name , 'input.md' ) )
238
+ /** @type {Node } */
239
+ const expected = JSON . parse (
246
240
String ( vfile . readSync ( path . join ( base , name , 'output.json' ) ) )
247
241
)
248
242
249
243
try {
250
244
options = JSON . parse (
251
245
String ( vfile . readSync ( path . join ( base , name , 'options.json' ) ) )
252
246
)
253
- } catch {
254
- options = undefined
255
- }
247
+ } catch { }
256
248
257
249
const processor = remark ( )
258
250
if ( options && options . useRemarkGfm ) processor . use ( gfm )
259
251
if ( options && options . useRemarkFrontmatter ) processor . use ( frontmatter )
260
-
261
- mdast = processor . parse ( input )
252
+ const mdast = /** @type {Root } */ ( processor . parse ( input ) )
262
253
263
254
t . deepEqual (
264
255
toNlcst ( mdast , input , ParseLatin , options ) ,
0 commit comments