@@ -19,6 +19,7 @@ var match = String.prototype.match;
19
19
var bigIntValueOf = typeof BigInt === 'function' ? BigInt . prototype . valueOf : null ;
20
20
var gOPS = Object . getOwnPropertySymbols ;
21
21
var symToString = typeof Symbol === 'function' && typeof Symbol . iterator === 'symbol' ? Symbol . prototype . toString : null ;
22
+ var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol . iterator === 'object' ;
22
23
var isEnumerable = Object . prototype . propertyIsEnumerable ;
23
24
24
25
var gPO = ( typeof Reflect === 'function' ? Reflect . getPrototypeOf : Object . getPrototypeOf ) || (
@@ -31,7 +32,7 @@ var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPr
31
32
32
33
var inspectCustom = require ( './util.inspect' ) . custom ;
33
34
var inspectSymbol = inspectCustom && isSymbol ( inspectCustom ) ? inspectCustom : null ;
34
- var toStringTag = typeof Symbol === 'function' && typeof Symbol . toStringTag === 'symbol ' ? Symbol . toStringTag : null ;
35
+ var toStringTag = typeof Symbol === 'function' && typeof Symbol . toStringTag !== 'undefined ' ? Symbol . toStringTag : null ;
35
36
36
37
module . exports = function inspect_ ( obj , options , depth , seen ) {
37
38
var opts = options || { } ;
@@ -121,8 +122,8 @@ module.exports = function inspect_(obj, options, depth, seen) {
121
122
return '[Function' + ( name ? ': ' + name : ' (anonymous)' ) + ']' + ( keys . length > 0 ? ' { ' + keys . join ( ', ' ) + ' }' : '' ) ;
122
123
}
123
124
if ( isSymbol ( obj ) ) {
124
- var symString = symToString . call ( obj ) ;
125
- return typeof obj === 'object' ? markBoxed ( symString ) : symString ;
125
+ var symString = hasShammedSymbols ? String ( obj ) . replace ( / ^ ( S y m b o l \( . * \) ) _ [ ^ ) ] * $ / , '$1' ) : symToString . call ( obj ) ;
126
+ return typeof obj === 'object' && ! hasShammedSymbols ? markBoxed ( symString ) : symString ;
126
127
}
127
128
if ( isElement ( obj ) ) {
128
129
var s = '<' + String ( obj . nodeName ) . toLowerCase ( ) ;
@@ -225,6 +226,9 @@ function isBoolean(obj) { return toStr(obj) === '[object Boolean]' && (!toString
225
226
226
227
// Symbol and BigInt do have Symbol.toStringTag by spec, so that can't be used to eliminate false positives
227
228
function isSymbol ( obj ) {
229
+ if ( hasShammedSymbols ) {
230
+ return obj && typeof obj === 'object' && obj instanceof Symbol ;
231
+ }
228
232
if ( typeof obj === 'symbol' ) {
229
233
return true ;
230
234
}
@@ -432,17 +436,28 @@ function arrObjKeys(obj, inspect) {
432
436
xs [ i ] = has ( obj , i ) ? inspect ( obj [ i ] , obj ) : '' ;
433
437
}
434
438
}
439
+ var syms = typeof gOPS === 'function' ? gOPS ( obj ) : [ ] ;
440
+ var symMap ;
441
+ if ( hasShammedSymbols ) {
442
+ symMap = { } ;
443
+ for ( var k = 0 ; k < syms . length ; k ++ ) {
444
+ symMap [ '$' + syms [ k ] ] = syms [ k ] ;
445
+ }
446
+ }
447
+
435
448
for ( var key in obj ) { // eslint-disable-line no-restricted-syntax
436
449
if ( ! has ( obj , key ) ) { continue ; } // eslint-disable-line no-restricted-syntax, no-continue
437
450
if ( isArr && String ( Number ( key ) ) === key && key < obj . length ) { continue ; } // eslint-disable-line no-restricted-syntax, no-continue
438
- if ( ( / [ ^ \w $ ] / ) . test ( key ) ) {
451
+ if ( hasShammedSymbols && symMap [ '$' + key ] instanceof Symbol ) {
452
+ // this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section
453
+ continue ; // eslint-disable-line no-restricted-syntax, no-continue
454
+ } else if ( ( / [ ^ \w $ ] / ) . test ( key ) ) {
439
455
xs . push ( inspect ( key , obj ) + ': ' + inspect ( obj [ key ] , obj ) ) ;
440
456
} else {
441
457
xs . push ( key + ': ' + inspect ( obj [ key ] , obj ) ) ;
442
458
}
443
459
}
444
460
if ( typeof gOPS === 'function' ) {
445
- var syms = gOPS ( obj ) ;
446
461
for ( var j = 0 ; j < syms . length ; j ++ ) {
447
462
if ( isEnumerable . call ( obj , syms [ j ] ) ) {
448
463
xs . push ( '[' + inspect ( syms [ j ] ) + ']: ' + inspect ( obj [ syms [ j ] ] , obj ) ) ;
0 commit comments