Skip to content

Commit

Permalink
don't copy global regexes in replaceAll
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Mar 23, 2019
1 parent 414ac97 commit 5b1b5db
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/core-js/modules/esnext.string.replace-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var requireObjectCoercible = require('../internals/require-object-coercible');
var isRegExp = require('../internals/is-regexp');
var getRegExpFlags = require('../internals/regexp-flags');
var ESCAPE_REGEXP = /[\\^$*+?.()|[\]{}]/g;
var speciesConstructor = require('../internals/species-constructor');

// `String.prototype.replaceAll` method
// https://github.com/tc39/proposal-string-replace-all
Expand All @@ -12,10 +12,11 @@ require('../internals/export')({ target: 'String', proto: true }, {
var search, flags;
if (isRegExp(searchValue)) {
flags = getRegExpFlags.call(searchValue);
search = new RegExp(searchValue.source, ~flags.indexOf('g') ? flags : flags + 'g');
} else {
search = new RegExp(String(searchValue).replace(ESCAPE_REGEXP, '\\$&'), 'g');
if (!~flags.indexOf('g')) {
search = new (speciesConstructor(searchValue, RegExp))(searchValue.source, flags + 'g');
} else search = searchValue;
return String(O).replace(search, replaceValue);
}
return String(O).replace(search, replaceValue);
return String(O).split(searchValue).join(replaceValue);
}
});

0 comments on commit 5b1b5db

Please sign in to comment.