5
5
6
6
import assert from 'assert'
7
7
import test from 'tape'
8
- // @ts -ignore remove when typed.
8
+ // @ts -expect-error remove when typed.
9
9
import retext from 'retext'
10
10
import { visit } from 'unist-util-visit'
11
11
import { isLiteral } from './index.js'
12
12
13
13
test ( 'isLiteral()' , ( t ) => {
14
14
t . throws (
15
15
( ) => {
16
- // @ts -ignore runtime.
16
+ // @ts -expect-error runtime.
17
17
isLiteral ( )
18
18
} ,
19
19
/ P a r e n t m u s t b e a n o d e / ,
@@ -22,7 +22,7 @@ test('isLiteral()', (t) => {
22
22
23
23
t . throws (
24
24
( ) => {
25
- // @ts -ignore runtime.
25
+ // @ts -expect-error runtime.
26
26
isLiteral ( { } )
27
27
} ,
28
28
/ P a r e n t m u s t b e a n o d e / ,
@@ -31,7 +31,7 @@ test('isLiteral()', (t) => {
31
31
32
32
t . throws (
33
33
( ) => {
34
- // @ts -ignore runtime.
34
+ // @ts -expect-error runtime.
35
35
isLiteral ( { children : [ ] } )
36
36
} ,
37
37
/ I n d e x m u s t b e a n u m b e r / ,
@@ -40,7 +40,7 @@ test('isLiteral()', (t) => {
40
40
41
41
t . throws (
42
42
( ) => {
43
- // @ts -ignore runtime.
43
+ // @ts -expect-error runtime.
44
44
isLiteral ( { children : [ ] } , { type : 'a' } )
45
45
} ,
46
46
/ N o d e m u s t b e a c h i l d o f ` p a r e n t ` / ,
@@ -49,15 +49,18 @@ test('isLiteral()', (t) => {
49
49
50
50
t . doesNotThrow ( ( ) => {
51
51
const n = { type : 'a' }
52
- // @ts -ignore runtime.
52
+ // @ts -expect-error runtime.
53
53
isLiteral ( { children : [ n ] } , n )
54
54
} , 'should not throw if `node` is in `parent`' )
55
55
56
56
t . doesNotThrow ( ( ) => {
57
57
process (
58
58
'Well? Ha! Funky' ,
59
59
/** @type {Visitor } */ ( _ , index , parent ) => {
60
- assert . strictEqual ( isLiteral ( parent , index ) , false )
60
+ assert . strictEqual (
61
+ parent && index !== null && isLiteral ( parent , index ) ,
62
+ false
63
+ )
61
64
}
62
65
)
63
66
} , 'should work on single word sentences' )
@@ -81,7 +84,7 @@ test('isLiteral()', (t) => {
81
84
fixtures [ index ] ,
82
85
/** @type {Visitor } */ ( _ , index , parent ) => {
83
86
assert . strictEqual (
84
- isLiteral ( parent , index ) ,
87
+ parent && index !== null && isLiteral ( parent , index ) ,
85
88
index === 0 ,
86
89
String ( index )
87
90
)
@@ -109,8 +112,8 @@ test('isLiteral()', (t) => {
109
112
fixtures [ index ] ,
110
113
/** @type {Visitor } */ ( _ , index , parent ) => {
111
114
assert . strictEqual (
112
- isLiteral ( parent , index ) ,
113
- index === parent . children . length - 2 ,
115
+ parent && index !== null && isLiteral ( parent , index ) ,
116
+ parent && index === parent . children . length - 2 ,
114
117
String ( index )
115
118
)
116
119
}
@@ -166,7 +169,7 @@ test('isLiteral()', (t) => {
166
169
}
167
170
168
171
assert . strictEqual (
169
- isLiteral ( parent , place ) ,
172
+ parent && place !== null && isLiteral ( parent , place ) ,
170
173
place === pos ,
171
174
String ( index )
172
175
)
0 commit comments