-
Notifications
You must be signed in to change notification settings - Fork 17
Conversation
LongTengDao
commented
May 28, 2019
•
edited
Loading
edited
- U+2028 U+2029
- -Infinity -0
- export default Date/RegExp
- export default <space> (even when compact) value (startsWith letter/number)
- export default { key: (when compact) value }
- fix empty key/identifier error (which already has test and should already be fixed)
* U+2028 U+2029 * -Infinity -0 * export default Date/RegExp * export default + space (even when compact) + value (startsWith letter/number)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice collection of edge cases! Just some minor comments.
src/dataToEsm.ts
Outdated
@@ -3,6 +3,10 @@ import { DataToEsm } from './pluginutils'; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see JSON.stringify(undefined)
returns undefined
. So maybe just add a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks a lot!