@@ -55,12 +55,26 @@ export default function stringifyObject(input, options, pad) {
5555 || typeof input === 'number'
5656 || typeof input === 'boolean'
5757 || typeof input === 'function'
58- || typeof input === 'symbol'
5958 || isRegexp ( input )
6059 ) {
6160 return String ( input ) ;
6261 }
6362
63+ if ( typeof input === 'symbol' ) {
64+ const t = input . description ;
65+ if ( t === undefined ) return 'Symbol()' ;
66+ if ( t . slice ( 0 , 7 ) === 'Symbol.'
67+ && Symbol [ t . slice ( 7 ) ] === input
68+ ) {
69+ return t ;
70+ }
71+ const q = stringify ( t , options ) ;
72+ if ( Symbol . keyFor ( input ) !== undefined ) {
73+ return `Symbol.for(${ q } )` ;
74+ }
75+ return `Symbol(${ q } )` ;
76+ }
77+
6478 if ( input instanceof Date ) {
6579 return `new Date('${ input . toISOString ( ) } ')` ;
6680 }
@@ -106,7 +120,9 @@ export default function stringifyObject(input, options, pad) {
106120 const eol = objectKeys . length - 1 === index ? tokens . newline : ',' + tokens . newlineOrSpace ;
107121 const isSymbol = typeof element === 'symbol' ;
108122 const isClassic = ! isSymbol && / ^ [ a - z $ _ ] [ $ \w ] * $ / i. test ( element ) ;
109- const key = isSymbol || isClassic ? element : stringify ( element , options ) ;
123+ let key = element ;
124+ if ( ! isClassic ) key = stringify ( element , options ) ;
125+ if ( isSymbol ) key = '[' + key + ']' ;
110126
111127 let value = stringify ( input [ element ] , options , pad + indent ) ;
112128 if ( options . transform ) {
0 commit comments