@@ -125,6 +125,8 @@ function replacer (key) {
125
125
return NEGATIVE_INFINITY
126
126
} else if ( type === 'function' ) {
127
127
return getCustomFunctionDetails ( val )
128
+ } else if ( type === 'symbol' ) {
129
+ return `[native Symbol ${ Symbol . prototype . toString . call ( val ) } ]`
128
130
} else if ( val !== null && type === 'object' ) {
129
131
if ( val instanceof Map ) {
130
132
return encodeCache . cache ( val , ( ) => getCustomMapDetails ( val ) )
@@ -251,8 +253,9 @@ export function getCustomFunctionDetails (func) {
251
253
} catch ( e ) {
252
254
// Func is probably a Proxy, which can break Function.prototype.toString()
253
255
}
254
- const matches = string . match ( / \( .* \) / )
255
- const args = matches ? matches [ 0 ] : '(?)'
256
+ const matches = string . match ( / \( [ \s \S ] * ?\) / )
257
+ // Trim any excess whitespace from the argument string
258
+ const args = matches ? `(${ matches [ 0 ] . substr ( 1 , matches [ 0 ] . length - 2 ) . split ( ',' ) . map ( a => a . trim ( ) ) . join ( ', ' ) } )` : '(?)'
256
259
return {
257
260
_custom : {
258
261
type : 'function' ,
@@ -268,6 +271,7 @@ export function parse (data, revive) {
268
271
}
269
272
270
273
const specialTypeRE = / ^ \[ n a t i v e ( \w + ) ( .* ) \] $ /
274
+ const symbolRE = / ^ \[ n a t i v e S y m b o l S y m b o l \( ( .* ) \) \] $ /
271
275
272
276
function reviver ( key , val ) {
273
277
if ( val === UNDEFINED ) {
@@ -286,6 +290,9 @@ function reviver (key, val) {
286
290
} else if ( val . _custom . type === 'set' ) {
287
291
return reviveSet ( val )
288
292
}
293
+ } else if ( symbolRE . test ( val ) ) {
294
+ const [ , string ] = symbolRE . exec ( val )
295
+ return Symbol . for ( string )
289
296
} else if ( specialTypeRE . test ( val ) ) {
290
297
const [ , type , string ] = specialTypeRE . exec ( val )
291
298
return new window [ type ] ( string )
0 commit comments