File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -135,9 +135,9 @@ export const stats = new Stats(_guard);
135
135
*/
136
136
137
137
138
- export function inspect ( value : any ) : string {
138
+ function _inspectString ( value : any , done : Set < any > ) : string {
139
139
if ( Array . isArray ( value ) ) {
140
- return "[" + value . map ( ( v ) => inspect ( v ) ) . join ( ", " ) + "]" ;
140
+ return "[" + value . map ( ( v ) => _inspect ( v , done ) ) . join ( ", " ) + "]" ;
141
141
}
142
142
143
143
switch ( typeof ( value ) ) {
@@ -152,10 +152,24 @@ export function inspect(value: any): string {
152
152
case "object" :
153
153
if ( value == null ) { return "null" ; }
154
154
return "{ " + Object . keys ( value ) . map ( ( key ) => {
155
- return `${ key } =${ inspect ( value [ key ] ) } ` ;
155
+ return `${ key } =${ _inspect ( value [ key ] , done ) } ` ;
156
156
} ) . join ( ", " ) + " }" ;
157
157
}
158
158
159
159
return `[ unknown type: ${ value } ]`
160
160
}
161
161
162
+ function _inspect ( value : any , done : Set < any > ) : string {
163
+ if ( done . has ( value ) ) { return "[ Circular ]" ; }
164
+
165
+ done . add ( value ) ;
166
+ const result = _inspectString ( value , done ) ;
167
+ done . delete ( value ) ;
168
+
169
+ return result ;
170
+ }
171
+
172
+ export function inspect ( value : any ) : string {
173
+ return _inspect ( value , new Set ( ) ) ;
174
+ }
175
+
You can’t perform that action at this time.
0 commit comments