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);
135135*/
136136
137137
138- export function inspect ( value : any ) : string {
138+ function _inspectString ( value : any , done : Set < any > ) : string {
139139 if ( Array . isArray ( value ) ) {
140- return "[" + value . map ( ( v ) => inspect ( v ) ) . join ( ", " ) + "]" ;
140+ return "[" + value . map ( ( v ) => _inspect ( v , done ) ) . join ( ", " ) + "]" ;
141141 }
142142
143143 switch ( typeof ( value ) ) {
@@ -152,10 +152,24 @@ export function inspect(value: any): string {
152152 case "object" :
153153 if ( value == null ) { return "null" ; }
154154 return "{ " + Object . keys ( value ) . map ( ( key ) => {
155- return `${ key } =${ inspect ( value [ key ] ) } ` ;
155+ return `${ key } =${ _inspect ( value [ key ] , done ) } ` ;
156156 } ) . join ( ", " ) + " }" ;
157157 }
158158
159159 return `[ unknown type: ${ value } ]`
160160}
161161
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