Skip to content

Commit 44e7235

Browse files
committed
fix: support symbol as object key
1 parent b66592f commit 44e7235

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

build/stringifier.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function createStringifier (customOptions) {
8585
return function stringifyAny (push, x) {
8686
var context = this;
8787
var handler = handlerFor(context.node, options, handlers);
88-
var currentPath = '/' + context.path.join('/');
88+
var currentPath = '/' + context.path.map(String).join('/');
8989
var customization = handlers[currentPath];
9090
var acc = {
9191
context: context,
@@ -1435,7 +1435,11 @@ function decorateObject () {
14351435
}
14361436

14371437
function sanitizeKey (key) {
1438-
return /^[A-Za-z_]+$/.test(key) ? key : JSON.stringify(key);
1438+
if (typeof key === 'symbol') {
1439+
return key.toString();
1440+
} else {
1441+
return /^[A-Za-z_]+$/.test(key) ? key : JSON.stringify(key);
1442+
}
14391443
}
14401444

14411445
function afterAllChildren (context, push, options) {

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function createStringifier (customOptions) {
5454
return function stringifyAny (push, x) {
5555
var context = this;
5656
var handler = handlerFor(context.node, options, handlers);
57-
var currentPath = '/' + context.path.join('/');
57+
var currentPath = '/' + context.path.map(String).join('/');
5858
var customization = handlers[currentPath];
5959
var acc = {
6060
context: context,

strategies.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,11 @@ function decorateObject () {
260260
}
261261

262262
function sanitizeKey (key) {
263-
return /^[A-Za-z_]+$/.test(key) ? key : JSON.stringify(key);
263+
if (typeof key === 'symbol') {
264+
return key.toString();
265+
} else {
266+
return /^[A-Za-z_]+$/.test(key) ? key : JSON.stringify(key);
267+
}
264268
}
265269

266270
function afterAllChildren (context, push, options) {

0 commit comments

Comments
 (0)