Sha256: 49d26a46ff43b398e6228aa2aa703b3ab9536cd97faca699b35e8ce8163dd7db

Contents?: true

Size: 1.62 KB

Versions: 9

Compression:

Stored size: 1.62 KB

Contents

'use strict';
var regexpFlags = require('./regexp-flags');

var nativeExec = RegExp.prototype.exec;
// This always refers to the native implementation, because the
// String#replace polyfill uses ./fix-regexp-well-known-symbol-logic.js,
// which loads this file before patching the method.
var nativeReplace = String.prototype.replace;

var patchedExec = nativeExec;

var UPDATES_LAST_INDEX_WRONG = (function () {
  var re1 = /a/;
  var re2 = /b*/g;
  nativeExec.call(re1, 'a');
  nativeExec.call(re2, 'a');
  return re1.lastIndex !== 0 || re2.lastIndex !== 0;
})();

// nonparticipating capturing group, copied from es5-shim's String#split patch.
var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;

var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED;

if (PATCH) {
  patchedExec = function exec(str) {
    var re = this;
    var lastIndex, reCopy, match, i;

    if (NPCG_INCLUDED) {
      reCopy = new RegExp('^' + re.source + '$(?!\\s)', regexpFlags.call(re));
    }
    if (UPDATES_LAST_INDEX_WRONG) lastIndex = re.lastIndex;

    match = nativeExec.call(re, str);

    if (UPDATES_LAST_INDEX_WRONG && match) {
      re.lastIndex = re.global ? match.index + match[0].length : lastIndex;
    }
    if (NPCG_INCLUDED && match && match.length > 1) {
      // Fix browsers whose `exec` methods don't consistently return `undefined`
      // for NPCG, like IE8. NOTE: This doesn' work for /(.?)?/
      nativeReplace.call(match[0], reCopy, function () {
        for (i = 1; i < arguments.length - 2; i++) {
          if (arguments[i] === undefined) match[i] = undefined;
        }
      });
    }

    return match;
  };
}

module.exports = patchedExec;

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/core-js/internals/regexp-exec.js
disco_app-0.18.2 test/dummy/node_modules/core-js/internals/regexp-exec.js
jester-data-8.0.0 node_modules/core-js/internals/regexp-exec.js
ezii-os-5.2.1 node_modules/core-js/internals/regexp-exec.js
ezii-os-2.0.1 node_modules/core-js/internals/regexp-exec.js
ezii-os-1.1.0 node_modules/core-js/internals/regexp-exec.js
ezii-os-1.0.0 node_modules/core-js/internals/regexp-exec.js
ezii-os-0.0.0.1.0 node_modules/core-js/internals/regexp-exec.js
ezii-os-0.0.0.0.1 node_modules/core-js/internals/regexp-exec.js