File tree Expand file tree Collapse file tree 2 files changed +94
-2
lines changed Expand file tree Collapse file tree 2 files changed +94
-2
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,19 @@ var CHAR_CONTINUE_AND_SPLIT = '├';
74
74
var CONTINUE = CHAR_CONTINUE_AND_SPLIT + CHAR_HORIZONTAL_LINE + ' ' ;
75
75
var STOP = CHAR_SPLIT + CHAR_HORIZONTAL_LINE + ' ' ;
76
76
77
+ /*
78
+ * Standard keys defined by unist:
79
+ * https://github.com/wooorm/unist.
80
+ * We don‘t include `data` though.
81
+ */
82
+
83
+ var ignore = [
84
+ 'type' ,
85
+ 'value' ,
86
+ 'children' ,
87
+ 'position'
88
+ ] ;
89
+
77
90
/**
78
91
* Colored nesting formatter.
79
92
*
@@ -161,6 +174,9 @@ function formatNode(node) {
161
174
var log = node . type ;
162
175
var location = node . position || { } ;
163
176
var position = stringify ( location . start , location . end ) ;
177
+ var key ;
178
+ var values = [ ] ;
179
+ var value ;
164
180
165
181
if ( node . children && node . children . length ) {
166
182
log += dim ( '[' ) + yellow ( node . children . length ) + dim ( ']' ) ;
@@ -172,8 +188,23 @@ function formatNode(node) {
172
188
log += ' (' + position + ')' ;
173
189
}
174
190
175
- if ( ! isEmpty ( node . data ) ) {
176
- log += ' [data=' + JSON . stringify ( node . data ) + ']' ;
191
+ for ( key in node ) {
192
+ value = node [ key ] ;
193
+
194
+ if (
195
+ ignore . indexOf ( key ) !== - 1 ||
196
+ value === null ||
197
+ value === undefined ||
198
+ ( typeof value === 'object' && isEmpty ( value ) )
199
+ ) {
200
+ continue ;
201
+ }
202
+
203
+ values . push ( '[' + key + '=' + JSON . stringify ( value ) + ']' ) ;
204
+ }
205
+
206
+ if ( values . length ) {
207
+ log += ' ' + values . join ( '' ) ;
177
208
}
178
209
179
210
return log ;
Original file line number Diff line number Diff line change @@ -145,6 +145,67 @@ test('inspect()', function (t) {
145
145
'should work with data attributes'
146
146
) ;
147
147
148
+ t . equal (
149
+ strip ( inspect ( {
150
+ 'type' : 'table' ,
151
+ 'align' : [ 'left' , 'center' ] ,
152
+ 'children' : [
153
+ {
154
+ 'type' : 'tableRow' ,
155
+ 'children' : [
156
+ {
157
+ 'type' : 'tableCell' ,
158
+ 'children' : [ {
159
+ 'type' : 'text' ,
160
+ 'value' : 'foo'
161
+ } ]
162
+ } ,
163
+ {
164
+ 'type' : 'tableCell' ,
165
+ 'children' : [ {
166
+ 'type' : 'text' ,
167
+ 'value' : 'bar'
168
+ } ]
169
+ }
170
+ ]
171
+ } ,
172
+ {
173
+ 'type' : 'tableRow' ,
174
+ 'children' : [
175
+ {
176
+ 'type' : 'tableCell' ,
177
+ 'children' : [ {
178
+ 'type' : 'text' ,
179
+ 'value' : 'baz'
180
+ } ]
181
+ } ,
182
+ {
183
+ 'type' : 'tableCell' ,
184
+ 'children' : [ {
185
+ 'type' : 'text' ,
186
+ 'value' : 'qux'
187
+ } ]
188
+ }
189
+ ]
190
+ }
191
+ ]
192
+ } ) ) ,
193
+ [
194
+ 'table[2] [align=["left","center"]]' ,
195
+ '├─ tableRow[2]' ,
196
+ '│ ├─ tableCell[1]' ,
197
+ '│ │ └─ text: "foo"' ,
198
+ '│ └─ tableCell[1]' ,
199
+ '│ └─ text: "bar"' ,
200
+ '└─ tableRow[2]' ,
201
+ ' ├─ tableCell[1]' ,
202
+ ' │ └─ text: "baz"' ,
203
+ ' └─ tableCell[1]' ,
204
+ ' └─ text: "qux"'
205
+ ] . join ( '\n' ) ,
206
+ 'should work with other attributes'
207
+ ) ;
208
+
148
209
t . equal (
149
210
strip ( inspect ( {
150
211
'type' : 'foo' ,
You can’t perform that action at this time.
0 commit comments