File tree 3 files changed +14
-2
lines changed
3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ function createStringifier (customOptions) {
53
53
return function stringifyAny ( push , x ) {
54
54
const context = this ;
55
55
let handler = handlerFor ( context . node , options , handlers ) ;
56
- const currentPath = '/' + context . path . join ( '/' ) ;
56
+ const currentPath = '/' + context . path . map ( String ) . join ( '/' ) ;
57
57
const customization = handlers [ currentPath ] ;
58
58
const acc = {
59
59
context : context ,
Original file line number Diff line number Diff line change @@ -244,7 +244,11 @@ function decorateObject () {
244
244
}
245
245
246
246
function sanitizeKey ( key ) {
247
- return / ^ [ A - Z a - z _ ] + $ / . test ( key ) ? key : JSON . stringify ( key ) ;
247
+ if ( typeof key === 'symbol' ) {
248
+ return key . toString ( ) ;
249
+ } else {
250
+ return / ^ [ A - Z a - z _ ] + $ / . test ( key ) ? key : JSON . stringify ( key ) ;
251
+ }
248
252
}
249
253
250
254
function afterAllChildren ( context , push , options ) {
Original file line number Diff line number Diff line change @@ -9,4 +9,12 @@ describe('ES6 features', () => {
9
9
it ( 'Symbol' , ( ) => {
10
10
assert . strictEqual ( stringify ( FOO ) , 'Symbol(FOO)' ) ;
11
11
} ) ;
12
+ it ( 'Symbol as Object key' , ( ) => {
13
+ const id = Symbol ( "id" ) ;
14
+ const user = {
15
+ name : "John" ,
16
+ [ id ] : 123
17
+ } ;
18
+ assert . strictEqual ( stringify ( user ) , 'Object{name:"John",Symbol(id):123}' ) ;
19
+ } ) ;
12
20
} ) ;
You can’t perform that action at this time.
0 commit comments