-
-
Notifications
You must be signed in to change notification settings - Fork 258
Use fromCodePoint to convert high value unicode entities #243
Conversation
Wouldn't rollup just bundle the polyfill in? Yeah we can drop it but not in this pr, would need to plan that out |
not sure how the bundling works, would need to check. But then npm/yarn couldn't do deduplicating correctly as we hard inline it and it also seems to modify globals. |
Oh - then we need to use a version that gives a reference rather than the actual polyfill - like this kind of thing var fromCodePoint = require('fromCodePoint');
fromCodePoint(); |
If the plan is to drop support for node < 4 anyway, what do you think of including an inline copy of the polyfill (the fn without updating |
In order to avoid modifying String as the polyfill does, I've copied the source from the polyfill and adapted it return the polyfill function if the native version does not exist. Once support for node versions that lack fromCodePoint is dropped, this polyfill can be removed.
Went ahead and made a copy of the polyfill and dropped the dependency. Made the necessary changes to adapt it to the babylon lint settings and avoid updating cc: @mathiasbynens - fyi on copying String.fromcodepoint (and thx for the polyfill!). |
LGTM! Thanks for the CC, @ryanjduffy — I appreciate the heads-up 👍 Ref. babel/babel#4315 for dropping Node.js < 4 (in which case the polyfill can be removed). |
Btw, since the goal is to decode HTML entities, consider using a library like he. |
High code point Unicode entity references are being truncated because
String.fromCharCode
can only return a 2-byte character whereasString.fromCodePoint
can return a 4-byte character. Interestingly, the existing test case includes an appropriately high code point reference but the expected result is the truncated value and not the truly expected value.With this change,
💩
is correctly converted to💩
instead of
(which would be the value of
).