@@ -1952,50 +1952,58 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
19521952
19531953// Verify that classes are properly inspected.
19541954[
1955+ /* eslint-disable spaced-comment, no-multi-spaces, brace-style */
19551956 // The whitespace is intentional.
1956- // eslint-disable-next-line no-multi-spaces
1957- [ class { } , 'class (anonymous) {} ' ] ,
1958- [ class extends Error { log ( ) { } } , 'class (anonymous) extends Error {}' ] ,
1959- [ class A { constructor ( a ) { this . a = a ; } log ( ) { return this . a ; } } ] ,
1957+ [ class { } , '[class (anonymous)]' ] ,
1958+ [ class extends Error { log ( ) { } } , '[ class (anonymous) extends Error] ' ] ,
1959+ [ class A { constructor ( a ) { this . a = a ; } log ( ) { return this . a ; } } ,
1960+ ' [class A]' ] ,
19601961 [ class
1961- // Random comments are part of the stringified result
1962- äß extends TypeError { } , 'class äß extends TypeError {}' ] ,
1963- // The whitespace and new line is intended!
1964- // eslint-disable-next-line no-multi-spaces
1965- [ class X extends Error
1966- // eslint-disable-next-line brace-style
1967- { } , 'class X extends Error {}' ]
1962+ // Random { // comments /* */ are part of the toString() result
1963+ /* eslint-disable-next-line space-before-blocks */
1964+ äß /**/ extends /*{*/ TypeError { } , '[class äß extends TypeError]' ] ,
1965+ /* The whitespace and new line is intended! */
1966+ // Foobar !!!
1967+ [ class X extends /****/ Error
1968+ // More comments
1969+ { } , '[class X extends Error]' ]
1970+ /* eslint-enable spaced-comment, no-multi-spaces, brace-style */
19681971] . forEach ( ( [ clazz , string ] ) => {
1969- if ( string === undefined )
1970- string = Function . prototype . toString . call ( clazz ) . split ( / \s + / ) . join ( ' ' ) ;
1971- const open = string . indexOf ( '{' ) ;
19721972 const inspected = util . inspect ( clazz ) ;
1973- assert . strictEqual ( inspected , ` ${ string . slice ( 0 , open + 1 ) } }` ) ;
1973+ assert . strictEqual ( inspected , string ) ;
19741974 Object . defineProperty ( clazz , Symbol . toStringTag , {
19751975 value : 'Woohoo'
19761976 } ) ;
1977- const parts = inspected . split ( ' ' ) ;
1978- parts . pop ( ) ;
1977+ const parts = inspected . slice ( 0 , - 1 ) . split ( ' ' ) ;
19791978 const [ , name , ...rest ] = parts ;
1979+ rest . unshift ( '[Woohoo]' ) ;
1980+ if ( rest . length ) {
1981+ rest [ rest . length - 1 ] += ']' ;
1982+ }
19801983 assert . strictEqual (
19811984 util . inspect ( clazz ) ,
1982- [ 'class' , name , '[Woohoo]' , ...rest , '{}' ] . join ( ' ' )
1985+ [ '[ class' , name , ...rest ] . join ( ' ' )
19831986 ) ;
19841987 Object . setPrototypeOf ( clazz , null ) ;
19851988 assert . strictEqual (
19861989 util . inspect ( clazz ) ,
1987- [ 'class' , name , '[null prototype] [Woohoo] ' , ...rest , '{}' ] . join ( ' ' )
1990+ [ '[ class' , name , '[null prototype]' , ...rest ] . join ( ' ' )
19881991 ) ;
19891992 Object . defineProperty ( clazz , 'name' , { value : 'Foo' } ) ;
19901993 const newName = name === '(anonymous)' ? 'Foo' : `${ name } [Foo]` ;
19911994 assert . strictEqual (
19921995 util . inspect ( clazz ) ,
1993- [ 'class' , newName , '[null prototype] [Woohoo] ' , ...rest , '{}' ] . join ( ' ' )
1996+ [ '[ class' , newName , '[null prototype]' , ...rest ] . join ( ' ' )
19941997 ) ;
19951998 Object . setPrototypeOf ( clazz , Number . prototype ) ;
19961999 assert . strictEqual (
19972000 util . inspect ( clazz ) ,
1998- [ 'class' , newName , '[Number] [Woohoo]' , ...rest , '{}' ] . join ( ' ' )
2001+ [ '[class' , newName , '[Number]' , ...rest ] . join ( ' ' )
2002+ ) ;
2003+ clazz . foo = true ;
2004+ assert . strictEqual (
2005+ util . inspect ( clazz ) ,
2006+ [ '[class' , newName , '[Number]' , ...rest , '{ foo: true }' ] . join ( ' ' )
19992007 ) ;
20002008} ) ;
20012009
0 commit comments