add support for edge cases - #64
Conversation
* U+2028 U+2029 * -Infinity -0 * export default Date/RegExp * export default + space (even when compact) + value (startsWith letter/number)
lukastaegert
left a comment
There was a problem hiding this comment.
Really nice collection of edge cases! Just some minor comments.
| export type Indent = string | null | undefined; | ||
|
|
||
| function stringify (obj :any) :string { | ||
| return (JSON.stringify(obj) || 'undefined').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029'); |
There was a problem hiding this comment.
What is the fallback undefined good for? If I remove it, no test turns red and I could not come up with a situation where JSON.stringify would return a falsy value.
There was a problem hiding this comment.
Maybe the regular expressions could be combined? Then it would be easy to add more characters to be escaped:
JSON.stringify(obj).replace(/[\u2028\u2029]/g, char => `\\u${char.charCodeAt(0).toString(16))}`;There was a problem hiding this comment.
Ah, I see JSON.stringify(undefined) returns undefined. So maybe just add a test.
There was a problem hiding this comment.
Ah, I see
JSON.stringify(undefined)returnsundefined. So maybe just add a test.
@lukastaegert Also JSON.stringify(function(){}). I added tests as your notice~
BTW: I can't figure out why the bug of empty key/identifier error happen, which should already be fixed even with test before this PR.
lukastaegert
left a comment
There was a problem hiding this comment.
Looks good, thanks a lot!
Uh oh!
There was an error while loading. Please reload this page.