-
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
jgeXml unconditionally overwrites String.prototype.replaceAll with its own version, which does not handle a Function as its second argument according to the spec:
Lines 3 to 9 in 82cb8c7
| Object.defineProperty(String.prototype,'replaceAll',{ | |
| value: function(search, replacement) { | |
| var target = this; | |
| return target.split(search).join(replacement); | |
| }, | |
| enumerable: false} | |
| ); |
This can break other code in the same project in interesting ways. For example, running the code
console.log('Before:', 'example'.replaceAll('e', (match, offset) => offset ? 'e!' : 'E'));
require('jgexml');
console.log('After:', 'example'.replaceAll('e', (match, offset) => offset ? 'e!' : 'E'));prints
Before: Example!
After: (match, offset) => offset ? 'e!' : 'E'xampl(match, offset) => offset ? 'e!' : 'E'
Note that jgexml is not used or called, simply required. This is surprising and was frustrating to track down.
Could you consider not modifying String.prototype.replaceAll (or any global variables or their properties) or, if you must, only polyfilling it when absent and using a spec-conformant polyfill?
Thanks for considering,
Kevin
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels