1
- 'use strict' ;
1
+ 'use strict'
2
2
3
3
/* Dependencies. */
4
- var assert = require ( 'assert' ) ;
5
- var array = require ( 'x-is-array' ) ;
6
- var object = require ( 'x-is-object' ) ;
4
+ var assert = require ( 'assert' )
5
+ var array = require ( 'x-is-array' )
6
+ var object = require ( 'x-is-object' )
7
7
8
- var inspect ;
8
+ var inspect
9
9
10
10
try {
11
11
// eslint-disable-next-line import/no-dynamic-require, no-useless-concat
12
- inspect = require ( 'ut' + 'il' ) . inspect ;
13
- } catch ( err ) { /* Empty. */ }
12
+ inspect = require ( 'ut' + 'il' ) . inspect
13
+ } catch ( err ) {
14
+ /* Empty. */
15
+ }
14
16
15
17
/* Expose. */
16
- exports = wrap ( unist ) ;
17
- module . exports = exports ;
18
+ exports = wrap ( unist )
19
+ module . exports = exports
18
20
19
- exports . parent = wrap ( parent ) ;
20
- exports . text = wrap ( text ) ;
21
- exports . void = wrap ( empty ) ;
22
- exports . wrap = wrap ;
21
+ exports . parent = wrap ( parent )
22
+ exports . text = wrap ( text )
23
+ exports . void = wrap ( empty )
24
+ exports . wrap = wrap
23
25
24
26
/* Identifier to check if a value is seen. */
25
- var ID = '__unist__' ;
27
+ var ID = '__unist__'
26
28
27
29
/* List of specced properties. */
28
- var defined = [ 'type' , 'value' , 'children' , 'position' ] ;
30
+ var defined = [ 'type' , 'value' , 'children' , 'position' ]
29
31
30
32
/* Wrapper around `Node` which adds the current node
31
33
* (and parent, if available), to the message. */
32
34
function wrap ( fn ) {
33
- return wrapped ;
35
+ return wrapped
34
36
35
37
function wrapped ( node , parent ) {
36
38
try {
37
- fn ( node , parent ) ;
39
+ fn ( node , parent )
38
40
} catch ( err ) {
39
41
if ( ! err [ ID ] ) {
40
- err [ ID ] = true ;
42
+ err [ ID ] = true
41
43
42
- err . message += ': `' + view ( node ) + '`' ;
44
+ err . message += ': `' + view ( node ) + '`'
43
45
44
46
if ( parent ) {
45
- err . message += ' in `' + view ( parent ) + '`' ;
47
+ err . message += ' in `' + view ( parent ) + '`'
46
48
}
47
49
}
48
50
49
- throw err ;
51
+ throw err
50
52
}
51
53
}
52
54
}
53
55
54
56
/* Assert. */
55
57
function unist ( node ) {
56
- var type ;
57
- var children ;
58
- var value ;
59
- var key ;
60
- var index ;
61
- var length ;
58
+ var type
59
+ var children
60
+ var value
61
+ var key
62
+ var index
63
+ var length
62
64
63
- assert . ok ( object ( node ) , 'node should be an object' ) ;
65
+ assert . ok ( object ( node ) , 'node should be an object' )
64
66
65
- type = node . type ;
66
- children = node . children ;
67
- value = node . value ;
67
+ type = node . type
68
+ children = node . children
69
+ value = node . value
68
70
69
- assert . ok ( 'type' in node , 'node should have a type' ) ;
70
- assert . equal ( typeof type , 'string' , '`type` should be a string' ) ;
71
- assert . notEqual ( type , '' , '`type` should not be empty' ) ;
71
+ assert . ok ( 'type' in node , 'node should have a type' )
72
+ assert . equal ( typeof type , 'string' , '`type` should be a string' )
73
+ assert . notEqual ( type , '' , '`type` should not be empty' )
72
74
73
75
if ( value != null ) {
74
- assert . equal ( typeof value , 'string' , '`value` should be a string' ) ;
76
+ assert . equal ( typeof value , 'string' , '`value` should be a string' )
75
77
}
76
78
77
- location ( node . position ) ;
79
+ location ( node . position )
78
80
79
81
for ( key in node ) {
80
82
if ( defined . indexOf ( key ) === - 1 ) {
81
- vanilla ( key , node [ key ] ) ;
83
+ vanilla ( key , node [ key ] )
82
84
}
83
85
}
84
86
85
87
if ( children != null ) {
86
- assert . ok ( array ( children ) , '`children` should be an array' ) ;
87
- index = - 1 ;
88
- length = children . length ;
88
+ assert . ok ( array ( children ) , '`children` should be an array' )
89
+ index = - 1
90
+ length = children . length
89
91
90
92
while ( ++ index < length ) {
91
- exports ( children [ index ] , node ) ;
93
+ exports ( children [ index ] , node )
92
94
}
93
95
}
94
96
}
@@ -97,9 +99,9 @@ function unist(node) {
97
99
* and re-parsed to the same (deep) value. */
98
100
function vanilla ( key , value ) {
99
101
try {
100
- assert . deepEqual ( value , JSON . parse ( JSON . stringify ( value ) ) ) ;
102
+ assert . deepEqual ( value , JSON . parse ( JSON . stringify ( value ) ) )
101
103
} catch ( err ) {
102
- assert . fail ( '' , '' , 'non-specced property `' + key + '` should be JSON' ) ;
104
+ assert . fail ( '' , '' , 'non-specced property `' + key + '` should be JSON' )
103
105
}
104
106
}
105
107
@@ -111,64 +113,67 @@ function view(value) {
111
113
/* eslint-disable no-else-return */
112
114
/* istanbul ignore else - Browser. */
113
115
if ( inspect ) {
114
- return inspect ( value , { colors : false } ) ;
116
+ return inspect ( value , { colors : false } )
115
117
} else {
116
- return JSON . stringify ( value ) ;
118
+ return JSON . stringify ( value )
117
119
}
118
120
} catch ( err ) {
119
121
/* istanbul ignore next - Cyclical. */
120
- return String ( value ) ;
122
+ return String ( value )
121
123
}
122
124
}
123
125
124
126
/* Assert `node` is a parent node. */
125
127
function parent ( node ) {
126
- unist ( node ) ;
128
+ unist ( node )
127
129
128
- assert . equal ( 'value' in node , false , 'parent should not have `value`' ) ;
129
- assert . ok ( 'children' in node , 'parent should have `children`' ) ;
130
+ assert . equal ( 'value' in node , false , 'parent should not have `value`' )
131
+ assert . ok ( 'children' in node , 'parent should have `children`' )
130
132
}
131
133
132
134
/* Assert `node` is a text node. */
133
135
function text ( node ) {
134
- unist ( node ) ;
136
+ unist ( node )
135
137
136
- assert . equal ( 'children' in node , false , 'text should not have `children`' ) ;
137
- assert . ok ( 'value' in node , 'text should have `value`' ) ;
138
+ assert . equal ( 'children' in node , false , 'text should not have `children`' )
139
+ assert . ok ( 'value' in node , 'text should have `value`' )
138
140
}
139
141
140
142
/* Assert `node` is a Unist node, but neither parent nor
141
143
* text. */
142
144
function empty ( node ) {
143
- unist ( node ) ;
145
+ unist ( node )
144
146
145
- assert . equal ( 'value' in node , false , 'void should not have `value`' ) ;
146
- assert . equal ( 'children' in node , false , 'void should not have `children`' ) ;
147
+ assert . equal ( 'value' in node , false , 'void should not have `value`' )
148
+ assert . equal ( 'children' in node , false , 'void should not have `children`' )
147
149
}
148
150
149
151
/* Assert `location` is a Unist Location. */
150
152
function location ( location ) {
151
153
if ( location != null ) {
152
- assert . ok ( object ( location ) , '`position` should be an object' ) ;
154
+ assert . ok ( object ( location ) , '`position` should be an object' )
153
155
154
- position ( location . start , 'position.start' ) ;
155
- position ( location . end , 'position.end' ) ;
156
+ position ( location . start , 'position.start' )
157
+ position ( location . end , 'position.end' )
156
158
}
157
159
}
158
160
159
161
/* Assert `location` is a Unist Location. */
160
162
function position ( position , name ) {
161
163
if ( position != null ) {
162
- assert . ok ( object ( position ) , '`' + name + '` should be an object' ) ;
164
+ assert . ok ( object ( position ) , '`' + name + '` should be an object' )
163
165
164
166
if ( position . line != null ) {
165
- assert . ok ( 'line' in position , '`' + name + '` should have numeric `line`' ) ;
166
- assert . ok ( position . line >= 1 , '`' + name + '.line` should be gte `1`' ) ;
167
+ assert . ok ( 'line' in position , '`' + name + '` should have numeric `line`' )
168
+ assert . ok ( position . line >= 1 , '`' + name + '.line` should be gte `1`' )
167
169
}
168
170
169
171
if ( position . column != null ) {
170
- assert . ok ( 'column' in position , '`' + name + '` should have numeric `column`' ) ;
171
- assert . ok ( position . column >= 1 , '`' + name + '.column` should be gte `1`' ) ;
172
+ assert . ok (
173
+ 'column' in position ,
174
+ '`' + name + '` should have numeric `column`'
175
+ )
176
+ assert . ok ( position . column >= 1 , '`' + name + '.column` should be gte `1`' )
172
177
}
173
178
}
174
179
}
0 commit comments