Skip to content

Commit

Permalink
fix: serialize arrays and objects
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 10, 2020
1 parent 4e38c6c commit 78730a5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/instrument/src/babel/mdx-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ const serialzeProp = (prop: any): string => {
return `"${prop.toString()}"`;
}
if (Array.isArray(prop)) {
return prop.map(p => serialzeProp(p));
return JSON.stringify(prop.map(p => serialzeProp(p)));
}
if (typeof prop === 'object') {
return JSON.stringify(
Object.keys(prop).reduce(
(acc, key) => ({ ...acc, [key]: serialzeProp(prop[key]) }),
{},
),
);
}
if (typeof prop === 'string') {
return `"${jsStringEscape(prop)}"`;
Expand Down

0 comments on commit 78730a5

Please sign in to comment.