core-js 2.5.7 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +1 -1
- package/README.md +62 -62
- package/bower.json +1 -1
- package/build/config.js +1 -0
- package/client/core.js +1337 -920
- package/client/core.min.js +5 -5
- package/client/core.min.js.map +1 -1
- package/client/library.js +121 -113
- package/client/library.min.js +5 -5
- package/client/library.min.js.map +1 -1
- package/client/shim.js +1207 -790
- package/client/shim.min.js +5 -5
- package/client/shim.min.js.map +1 -1
- package/es6/index.js +1 -0
- package/es6/regexp.js +1 -0
- package/fn/regexp/index.js +1 -0
- package/library/es6/index.js +1 -0
- package/library/es6/regexp.js +1 -0
- package/library/fn/regexp/index.js +1 -0
- package/library/modules/_advance-string-index.js +8 -0
- package/library/modules/_core.js +1 -1
- package/library/modules/_fix-re-wks.js +74 -6
- package/library/modules/_regexp-exec-abstract.js +1 -0
- package/library/modules/_regexp-exec.js +1 -0
- package/library/modules/_shared.js +1 -1
- package/library/modules/es6.regexp.exec.js +1 -0
- package/library/shim.js +1 -0
- package/modules/_advance-string-index.js +8 -0
- package/modules/_core.js +1 -1
- package/modules/_fix-re-wks.js +74 -6
- package/modules/_regexp-exec-abstract.js +21 -0
- package/modules/_regexp-exec.js +58 -0
- package/modules/_shared.js +1 -1
- package/modules/es6.regexp.exec.js +9 -0
- package/modules/es6.regexp.match.js +38 -8
- package/modules/es6.regexp.replace.js +116 -10
- package/modules/es6.regexp.search.js +29 -8
- package/modules/es6.regexp.split.js +94 -31
- package/modules/library/_regexp-exec-abstract.js +1 -0
- package/modules/library/_regexp-exec.js +1 -0
- package/modules/library/es6.regexp.exec.js +1 -0
- package/package.json +1 -1
- package/shim.js +1 -0
package/es6/index.js
CHANGED
|
@@ -99,6 +99,7 @@ require('../modules/es6.array.find-index');
|
|
|
99
99
|
require('../modules/es6.array.species');
|
|
100
100
|
require('../modules/es6.array.iterator');
|
|
101
101
|
require('../modules/es6.regexp.constructor');
|
|
102
|
+
require('../modules/es6.regexp.exec');
|
|
102
103
|
require('../modules/es6.regexp.to-string');
|
|
103
104
|
require('../modules/es6.regexp.flags');
|
|
104
105
|
require('../modules/es6.regexp.match');
|
package/es6/regexp.js
CHANGED
package/fn/regexp/index.js
CHANGED
package/library/es6/index.js
CHANGED
|
@@ -99,6 +99,7 @@ require('../modules/es6.array.find-index');
|
|
|
99
99
|
require('../modules/es6.array.species');
|
|
100
100
|
require('../modules/es6.array.iterator');
|
|
101
101
|
require('../modules/es6.regexp.constructor');
|
|
102
|
+
require('../modules/es6.regexp.exec');
|
|
102
103
|
require('../modules/es6.regexp.to-string');
|
|
103
104
|
require('../modules/es6.regexp.flags');
|
|
104
105
|
require('../modules/es6.regexp.match');
|
package/library/es6/regexp.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var at = require('./_string-at')(true);
|
|
3
|
+
|
|
4
|
+
// `AdvanceStringIndex` abstract operation
|
|
5
|
+
// https://tc39.github.io/ecma262/#sec-advancestringindex
|
|
6
|
+
module.exports = function (S, index, unicode) {
|
|
7
|
+
return index + (unicode ? at(S, index).length : 1);
|
|
8
|
+
};
|
package/library/modules/_core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var core = module.exports = { version: '2.
|
|
1
|
+
var core = module.exports = { version: '2.6.3' };
|
|
2
2
|
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
|
|
@@ -1,20 +1,88 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
require('./es6.regexp.exec');
|
|
3
3
|
var redefine = require('./_redefine');
|
|
4
|
+
var hide = require('./_hide');
|
|
4
5
|
var fails = require('./_fails');
|
|
5
6
|
var defined = require('./_defined');
|
|
6
7
|
var wks = require('./_wks');
|
|
8
|
+
var regexpExec = require('./_regexp-exec');
|
|
9
|
+
|
|
10
|
+
var SPECIES = wks('species');
|
|
11
|
+
|
|
12
|
+
var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () {
|
|
13
|
+
// #replace needs built-in support for named groups.
|
|
14
|
+
// #match works fine because it just return the exec results, even if it has
|
|
15
|
+
// a "grops" property.
|
|
16
|
+
var re = /./;
|
|
17
|
+
re.exec = function () {
|
|
18
|
+
var result = [];
|
|
19
|
+
result.groups = { a: '7' };
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
return ''.replace(re, '$<a>') !== '7';
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = (function () {
|
|
26
|
+
// Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
|
|
27
|
+
var re = /(?:)/;
|
|
28
|
+
var originalExec = re.exec;
|
|
29
|
+
re.exec = function () { return originalExec.apply(this, arguments); };
|
|
30
|
+
var result = 'ab'.split(re);
|
|
31
|
+
return result.length === 2 && result[0] === 'a' && result[1] === 'b';
|
|
32
|
+
})();
|
|
7
33
|
|
|
8
34
|
module.exports = function (KEY, length, exec) {
|
|
9
35
|
var SYMBOL = wks(KEY);
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
if (fails(function () {
|
|
36
|
+
|
|
37
|
+
var DELEGATES_TO_SYMBOL = !fails(function () {
|
|
38
|
+
// String methods call symbol-named RegEp methods
|
|
14
39
|
var O = {};
|
|
15
40
|
O[SYMBOL] = function () { return 7; };
|
|
16
41
|
return ''[KEY](O) != 7;
|
|
17
|
-
})
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL ? !fails(function () {
|
|
45
|
+
// Symbol-named RegExp methods call .exec
|
|
46
|
+
var execCalled = false;
|
|
47
|
+
var re = /a/;
|
|
48
|
+
re.exec = function () { execCalled = true; return null; };
|
|
49
|
+
if (KEY === 'split') {
|
|
50
|
+
// RegExp[@@split] doesn't call the regex's exec method, but first creates
|
|
51
|
+
// a new one. We need to return the patched regex when creating the new one.
|
|
52
|
+
re.constructor = {};
|
|
53
|
+
re.constructor[SPECIES] = function () { return re; };
|
|
54
|
+
}
|
|
55
|
+
re[SYMBOL]('');
|
|
56
|
+
return !execCalled;
|
|
57
|
+
}) : undefined;
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
!DELEGATES_TO_SYMBOL ||
|
|
61
|
+
!DELEGATES_TO_EXEC ||
|
|
62
|
+
(KEY === 'replace' && !REPLACE_SUPPORTS_NAMED_GROUPS) ||
|
|
63
|
+
(KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC)
|
|
64
|
+
) {
|
|
65
|
+
var nativeRegExpMethod = /./[SYMBOL];
|
|
66
|
+
var fns = exec(
|
|
67
|
+
defined,
|
|
68
|
+
SYMBOL,
|
|
69
|
+
''[KEY],
|
|
70
|
+
function maybeCallNative(nativeMethod, regexp, str, arg2, forceStringMethod) {
|
|
71
|
+
if (regexp.exec === regexpExec) {
|
|
72
|
+
if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
|
|
73
|
+
// The native String method already delegates to @@method (this
|
|
74
|
+
// polyfilled function), leasing to infinite recursion.
|
|
75
|
+
// We avoid it by directly calling the native @@method method.
|
|
76
|
+
return { done: true, value: nativeRegExpMethod.call(regexp, str, arg2) };
|
|
77
|
+
}
|
|
78
|
+
return { done: true, value: nativeMethod.call(str, regexp, arg2) };
|
|
79
|
+
}
|
|
80
|
+
return { done: false };
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
var strfn = fns[0];
|
|
84
|
+
var rxfn = fns[1];
|
|
85
|
+
|
|
18
86
|
redefine(String.prototype, KEY, strfn);
|
|
19
87
|
hide(RegExp.prototype, SYMBOL, length == 2
|
|
20
88
|
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// empty
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// empty
|
|
@@ -8,5 +8,5 @@ var store = global[SHARED] || (global[SHARED] = {});
|
|
|
8
8
|
})('versions', []).push({
|
|
9
9
|
version: core.version,
|
|
10
10
|
mode: require('./_library') ? 'pure' : 'global',
|
|
11
|
-
copyright: '©
|
|
11
|
+
copyright: '© 2019 Denis Pushkarev (zloirock.ru)'
|
|
12
12
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// empty
|
package/library/shim.js
CHANGED
|
@@ -99,6 +99,7 @@ require('./modules/es6.array.find-index');
|
|
|
99
99
|
require('./modules/es6.array.species');
|
|
100
100
|
require('./modules/es6.array.iterator');
|
|
101
101
|
require('./modules/es6.regexp.constructor');
|
|
102
|
+
require('./modules/es6.regexp.exec');
|
|
102
103
|
require('./modules/es6.regexp.to-string');
|
|
103
104
|
require('./modules/es6.regexp.flags');
|
|
104
105
|
require('./modules/es6.regexp.match');
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var at = require('./_string-at')(true);
|
|
3
|
+
|
|
4
|
+
// `AdvanceStringIndex` abstract operation
|
|
5
|
+
// https://tc39.github.io/ecma262/#sec-advancestringindex
|
|
6
|
+
module.exports = function (S, index, unicode) {
|
|
7
|
+
return index + (unicode ? at(S, index).length : 1);
|
|
8
|
+
};
|
package/modules/_core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var core = module.exports = { version: '2.
|
|
1
|
+
var core = module.exports = { version: '2.6.3' };
|
|
2
2
|
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
|
package/modules/_fix-re-wks.js
CHANGED
|
@@ -1,20 +1,88 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
require('./es6.regexp.exec');
|
|
3
3
|
var redefine = require('./_redefine');
|
|
4
|
+
var hide = require('./_hide');
|
|
4
5
|
var fails = require('./_fails');
|
|
5
6
|
var defined = require('./_defined');
|
|
6
7
|
var wks = require('./_wks');
|
|
8
|
+
var regexpExec = require('./_regexp-exec');
|
|
9
|
+
|
|
10
|
+
var SPECIES = wks('species');
|
|
11
|
+
|
|
12
|
+
var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () {
|
|
13
|
+
// #replace needs built-in support for named groups.
|
|
14
|
+
// #match works fine because it just return the exec results, even if it has
|
|
15
|
+
// a "grops" property.
|
|
16
|
+
var re = /./;
|
|
17
|
+
re.exec = function () {
|
|
18
|
+
var result = [];
|
|
19
|
+
result.groups = { a: '7' };
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
return ''.replace(re, '$<a>') !== '7';
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = (function () {
|
|
26
|
+
// Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
|
|
27
|
+
var re = /(?:)/;
|
|
28
|
+
var originalExec = re.exec;
|
|
29
|
+
re.exec = function () { return originalExec.apply(this, arguments); };
|
|
30
|
+
var result = 'ab'.split(re);
|
|
31
|
+
return result.length === 2 && result[0] === 'a' && result[1] === 'b';
|
|
32
|
+
})();
|
|
7
33
|
|
|
8
34
|
module.exports = function (KEY, length, exec) {
|
|
9
35
|
var SYMBOL = wks(KEY);
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
if (fails(function () {
|
|
36
|
+
|
|
37
|
+
var DELEGATES_TO_SYMBOL = !fails(function () {
|
|
38
|
+
// String methods call symbol-named RegEp methods
|
|
14
39
|
var O = {};
|
|
15
40
|
O[SYMBOL] = function () { return 7; };
|
|
16
41
|
return ''[KEY](O) != 7;
|
|
17
|
-
})
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL ? !fails(function () {
|
|
45
|
+
// Symbol-named RegExp methods call .exec
|
|
46
|
+
var execCalled = false;
|
|
47
|
+
var re = /a/;
|
|
48
|
+
re.exec = function () { execCalled = true; return null; };
|
|
49
|
+
if (KEY === 'split') {
|
|
50
|
+
// RegExp[@@split] doesn't call the regex's exec method, but first creates
|
|
51
|
+
// a new one. We need to return the patched regex when creating the new one.
|
|
52
|
+
re.constructor = {};
|
|
53
|
+
re.constructor[SPECIES] = function () { return re; };
|
|
54
|
+
}
|
|
55
|
+
re[SYMBOL]('');
|
|
56
|
+
return !execCalled;
|
|
57
|
+
}) : undefined;
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
!DELEGATES_TO_SYMBOL ||
|
|
61
|
+
!DELEGATES_TO_EXEC ||
|
|
62
|
+
(KEY === 'replace' && !REPLACE_SUPPORTS_NAMED_GROUPS) ||
|
|
63
|
+
(KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC)
|
|
64
|
+
) {
|
|
65
|
+
var nativeRegExpMethod = /./[SYMBOL];
|
|
66
|
+
var fns = exec(
|
|
67
|
+
defined,
|
|
68
|
+
SYMBOL,
|
|
69
|
+
''[KEY],
|
|
70
|
+
function maybeCallNative(nativeMethod, regexp, str, arg2, forceStringMethod) {
|
|
71
|
+
if (regexp.exec === regexpExec) {
|
|
72
|
+
if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
|
|
73
|
+
// The native String method already delegates to @@method (this
|
|
74
|
+
// polyfilled function), leasing to infinite recursion.
|
|
75
|
+
// We avoid it by directly calling the native @@method method.
|
|
76
|
+
return { done: true, value: nativeRegExpMethod.call(regexp, str, arg2) };
|
|
77
|
+
}
|
|
78
|
+
return { done: true, value: nativeMethod.call(str, regexp, arg2) };
|
|
79
|
+
}
|
|
80
|
+
return { done: false };
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
var strfn = fns[0];
|
|
84
|
+
var rxfn = fns[1];
|
|
85
|
+
|
|
18
86
|
redefine(String.prototype, KEY, strfn);
|
|
19
87
|
hide(RegExp.prototype, SYMBOL, length == 2
|
|
20
88
|
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var classof = require('./_classof');
|
|
4
|
+
var builtinExec = RegExp.prototype.exec;
|
|
5
|
+
|
|
6
|
+
// `RegExpExec` abstract operation
|
|
7
|
+
// https://tc39.github.io/ecma262/#sec-regexpexec
|
|
8
|
+
module.exports = function (R, S) {
|
|
9
|
+
var exec = R.exec;
|
|
10
|
+
if (typeof exec === 'function') {
|
|
11
|
+
var result = exec.call(R, S);
|
|
12
|
+
if (typeof result !== 'object') {
|
|
13
|
+
throw new TypeError('RegExp exec method returned something other than an Object or null');
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
if (classof(R) !== 'RegExp') {
|
|
18
|
+
throw new TypeError('RegExp#exec called on incompatible receiver');
|
|
19
|
+
}
|
|
20
|
+
return builtinExec.call(R, S);
|
|
21
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var regexpFlags = require('./_flags');
|
|
4
|
+
|
|
5
|
+
var nativeExec = RegExp.prototype.exec;
|
|
6
|
+
// This always refers to the native implementation, because the
|
|
7
|
+
// String#replace polyfill uses ./fix-regexp-well-known-symbol-logic.js,
|
|
8
|
+
// which loads this file before patching the method.
|
|
9
|
+
var nativeReplace = String.prototype.replace;
|
|
10
|
+
|
|
11
|
+
var patchedExec = nativeExec;
|
|
12
|
+
|
|
13
|
+
var LAST_INDEX = 'lastIndex';
|
|
14
|
+
|
|
15
|
+
var UPDATES_LAST_INDEX_WRONG = (function () {
|
|
16
|
+
var re1 = /a/,
|
|
17
|
+
re2 = /b*/g;
|
|
18
|
+
nativeExec.call(re1, 'a');
|
|
19
|
+
nativeExec.call(re2, 'a');
|
|
20
|
+
return re1[LAST_INDEX] !== 0 || re2[LAST_INDEX] !== 0;
|
|
21
|
+
})();
|
|
22
|
+
|
|
23
|
+
// nonparticipating capturing group, copied from es5-shim's String#split patch.
|
|
24
|
+
var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;
|
|
25
|
+
|
|
26
|
+
var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED;
|
|
27
|
+
|
|
28
|
+
if (PATCH) {
|
|
29
|
+
patchedExec = function exec(str) {
|
|
30
|
+
var re = this;
|
|
31
|
+
var lastIndex, reCopy, match, i;
|
|
32
|
+
|
|
33
|
+
if (NPCG_INCLUDED) {
|
|
34
|
+
reCopy = new RegExp('^' + re.source + '$(?!\\s)', regexpFlags.call(re));
|
|
35
|
+
}
|
|
36
|
+
if (UPDATES_LAST_INDEX_WRONG) lastIndex = re[LAST_INDEX];
|
|
37
|
+
|
|
38
|
+
match = nativeExec.call(re, str);
|
|
39
|
+
|
|
40
|
+
if (UPDATES_LAST_INDEX_WRONG && match) {
|
|
41
|
+
re[LAST_INDEX] = re.global ? match.index + match[0].length : lastIndex;
|
|
42
|
+
}
|
|
43
|
+
if (NPCG_INCLUDED && match && match.length > 1) {
|
|
44
|
+
// Fix browsers whose `exec` methods don't consistently return `undefined`
|
|
45
|
+
// for NPCG, like IE8. NOTE: This doesn' work for /(.?)?/
|
|
46
|
+
// eslint-disable-next-line no-loop-func
|
|
47
|
+
nativeReplace.call(match[0], reCopy, function () {
|
|
48
|
+
for (i = 1; i < arguments.length - 2; i++) {
|
|
49
|
+
if (arguments[i] === undefined) match[i] = undefined;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return match;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = patchedExec;
|
package/modules/_shared.js
CHANGED
|
@@ -8,5 +8,5 @@ var store = global[SHARED] || (global[SHARED] = {});
|
|
|
8
8
|
})('versions', []).push({
|
|
9
9
|
version: core.version,
|
|
10
10
|
mode: require('./_library') ? 'pure' : 'global',
|
|
11
|
-
copyright: '©
|
|
11
|
+
copyright: '© 2019 Denis Pushkarev (zloirock.ru)'
|
|
12
12
|
});
|
|
@@ -1,10 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var anObject = require('./_an-object');
|
|
4
|
+
var toLength = require('./_to-length');
|
|
5
|
+
var advanceStringIndex = require('./_advance-string-index');
|
|
6
|
+
var regExpExec = require('./_regexp-exec-abstract');
|
|
7
|
+
|
|
1
8
|
// @@match logic
|
|
2
|
-
require('./_fix-re-wks')('match', 1, function (defined, MATCH, $match) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
require('./_fix-re-wks')('match', 1, function (defined, MATCH, $match, maybeCallNative) {
|
|
10
|
+
return [
|
|
11
|
+
// `String.prototype.match` method
|
|
12
|
+
// https://tc39.github.io/ecma262/#sec-string.prototype.match
|
|
13
|
+
function match(regexp) {
|
|
14
|
+
var O = defined(this);
|
|
15
|
+
var fn = regexp == undefined ? undefined : regexp[MATCH];
|
|
16
|
+
return fn !== undefined ? fn.call(regexp, O) : new RegExp(regexp)[MATCH](String(O));
|
|
17
|
+
},
|
|
18
|
+
// `RegExp.prototype[@@match]` method
|
|
19
|
+
// https://tc39.github.io/ecma262/#sec-regexp.prototype-@@match
|
|
20
|
+
function (regexp) {
|
|
21
|
+
var res = maybeCallNative($match, regexp, this);
|
|
22
|
+
if (res.done) return res.value;
|
|
23
|
+
var rx = anObject(regexp);
|
|
24
|
+
var S = String(this);
|
|
25
|
+
if (!rx.global) return regExpExec(rx, S);
|
|
26
|
+
var fullUnicode = rx.unicode;
|
|
27
|
+
rx.lastIndex = 0;
|
|
28
|
+
var A = [];
|
|
29
|
+
var n = 0;
|
|
30
|
+
var result;
|
|
31
|
+
while ((result = regExpExec(rx, S)) !== null) {
|
|
32
|
+
var matchStr = String(result[0]);
|
|
33
|
+
A[n] = matchStr;
|
|
34
|
+
if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode);
|
|
35
|
+
n++;
|
|
36
|
+
}
|
|
37
|
+
return n === 0 ? null : A;
|
|
38
|
+
}
|
|
39
|
+
];
|
|
10
40
|
});
|
|
@@ -1,12 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var anObject = require('./_an-object');
|
|
4
|
+
var toObject = require('./_to-object');
|
|
5
|
+
var toLength = require('./_to-length');
|
|
6
|
+
var toInteger = require('./_to-integer');
|
|
7
|
+
var advanceStringIndex = require('./_advance-string-index');
|
|
8
|
+
var regExpExec = require('./_regexp-exec-abstract');
|
|
9
|
+
var max = Math.max;
|
|
10
|
+
var min = Math.min;
|
|
11
|
+
var floor = Math.floor;
|
|
12
|
+
var SUBSTITUTION_SYMBOLS = /\$([$&`']|\d\d?|<[^>]*>)/g;
|
|
13
|
+
var SUBSTITUTION_SYMBOLS_NO_NAMED = /\$([$&`']|\d\d?)/g;
|
|
14
|
+
|
|
15
|
+
var maybeToString = function (it) {
|
|
16
|
+
return it === undefined ? it : String(it);
|
|
17
|
+
};
|
|
18
|
+
|
|
1
19
|
// @@replace logic
|
|
2
|
-
require('./_fix-re-wks')('replace', 2, function (defined, REPLACE, $replace) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
require('./_fix-re-wks')('replace', 2, function (defined, REPLACE, $replace, maybeCallNative) {
|
|
21
|
+
return [
|
|
22
|
+
// `String.prototype.replace` method
|
|
23
|
+
// https://tc39.github.io/ecma262/#sec-string.prototype.replace
|
|
24
|
+
function replace(searchValue, replaceValue) {
|
|
25
|
+
var O = defined(this);
|
|
26
|
+
var fn = searchValue == undefined ? undefined : searchValue[REPLACE];
|
|
27
|
+
return fn !== undefined
|
|
28
|
+
? fn.call(searchValue, O, replaceValue)
|
|
29
|
+
: $replace.call(String(O), searchValue, replaceValue);
|
|
30
|
+
},
|
|
31
|
+
// `RegExp.prototype[@@replace]` method
|
|
32
|
+
// https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace
|
|
33
|
+
function (regexp, replaceValue) {
|
|
34
|
+
var res = maybeCallNative($replace, regexp, this, replaceValue);
|
|
35
|
+
if (res.done) return res.value;
|
|
36
|
+
|
|
37
|
+
var rx = anObject(regexp);
|
|
38
|
+
var S = String(this);
|
|
39
|
+
var functionalReplace = typeof replaceValue === 'function';
|
|
40
|
+
if (!functionalReplace) replaceValue = String(replaceValue);
|
|
41
|
+
var global = rx.global;
|
|
42
|
+
if (global) {
|
|
43
|
+
var fullUnicode = rx.unicode;
|
|
44
|
+
rx.lastIndex = 0;
|
|
45
|
+
}
|
|
46
|
+
var results = [];
|
|
47
|
+
while (true) {
|
|
48
|
+
var result = regExpExec(rx, S);
|
|
49
|
+
if (result === null) break;
|
|
50
|
+
results.push(result);
|
|
51
|
+
if (!global) break;
|
|
52
|
+
var matchStr = String(result[0]);
|
|
53
|
+
if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode);
|
|
54
|
+
}
|
|
55
|
+
var accumulatedResult = '';
|
|
56
|
+
var nextSourcePosition = 0;
|
|
57
|
+
for (var i = 0; i < results.length; i++) {
|
|
58
|
+
result = results[i];
|
|
59
|
+
var matched = String(result[0]);
|
|
60
|
+
var position = max(min(toInteger(result.index), S.length), 0);
|
|
61
|
+
var captures = [];
|
|
62
|
+
// NOTE: This is equivalent to
|
|
63
|
+
// captures = result.slice(1).map(maybeToString)
|
|
64
|
+
// but for some reason `nativeSlice.call(result, 1, result.length)` (called in
|
|
65
|
+
// the slice polyfill when slicing native arrays) "doesn't work" in safari 9 and
|
|
66
|
+
// causes a crash (https://pastebin.com/N21QzeQA) when trying to debug it.
|
|
67
|
+
for (var j = 1; j < result.length; j++) captures.push(maybeToString(result[j]));
|
|
68
|
+
var namedCaptures = result.groups;
|
|
69
|
+
if (functionalReplace) {
|
|
70
|
+
var replacerArgs = [matched].concat(captures, position, S);
|
|
71
|
+
if (namedCaptures !== undefined) replacerArgs.push(namedCaptures);
|
|
72
|
+
var replacement = String(replaceValue.apply(undefined, replacerArgs));
|
|
73
|
+
} else {
|
|
74
|
+
replacement = getSubstitution(matched, S, position, captures, namedCaptures, replaceValue);
|
|
75
|
+
}
|
|
76
|
+
if (position >= nextSourcePosition) {
|
|
77
|
+
accumulatedResult += S.slice(nextSourcePosition, position) + replacement;
|
|
78
|
+
nextSourcePosition = position + matched.length;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return accumulatedResult + S.slice(nextSourcePosition);
|
|
82
|
+
}
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
// https://tc39.github.io/ecma262/#sec-getsubstitution
|
|
86
|
+
function getSubstitution(matched, str, position, captures, namedCaptures, replacement) {
|
|
87
|
+
var tailPos = position + matched.length;
|
|
88
|
+
var m = captures.length;
|
|
89
|
+
var symbols = SUBSTITUTION_SYMBOLS_NO_NAMED;
|
|
90
|
+
if (namedCaptures !== undefined) {
|
|
91
|
+
namedCaptures = toObject(namedCaptures);
|
|
92
|
+
symbols = SUBSTITUTION_SYMBOLS;
|
|
93
|
+
}
|
|
94
|
+
return $replace.call(replacement, symbols, function (match, ch) {
|
|
95
|
+
var capture;
|
|
96
|
+
switch (ch.charAt(0)) {
|
|
97
|
+
case '$': return '$';
|
|
98
|
+
case '&': return matched;
|
|
99
|
+
case '`': return str.slice(0, position);
|
|
100
|
+
case "'": return str.slice(tailPos);
|
|
101
|
+
case '<':
|
|
102
|
+
capture = namedCaptures[ch.slice(1, -1)];
|
|
103
|
+
break;
|
|
104
|
+
default: // \d\d?
|
|
105
|
+
var n = +ch;
|
|
106
|
+
if (n === 0) return match;
|
|
107
|
+
if (n > m) {
|
|
108
|
+
var f = floor(n / 10);
|
|
109
|
+
if (f === 0) return match;
|
|
110
|
+
if (f <= m) return captures[f - 1] === undefined ? ch.charAt(1) : captures[f - 1] + ch.charAt(1);
|
|
111
|
+
return match;
|
|
112
|
+
}
|
|
113
|
+
capture = captures[n - 1];
|
|
114
|
+
}
|
|
115
|
+
return capture === undefined ? '' : capture;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
12
118
|
});
|
|
@@ -1,10 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var anObject = require('./_an-object');
|
|
4
|
+
var sameValue = require('./_same-value');
|
|
5
|
+
var regExpExec = require('./_regexp-exec-abstract');
|
|
6
|
+
|
|
1
7
|
// @@search logic
|
|
2
|
-
require('./_fix-re-wks')('search', 1, function (defined, SEARCH, $search) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
require('./_fix-re-wks')('search', 1, function (defined, SEARCH, $search, maybeCallNative) {
|
|
9
|
+
return [
|
|
10
|
+
// `String.prototype.search` method
|
|
11
|
+
// https://tc39.github.io/ecma262/#sec-string.prototype.search
|
|
12
|
+
function search(regexp) {
|
|
13
|
+
var O = defined(this);
|
|
14
|
+
var fn = regexp == undefined ? undefined : regexp[SEARCH];
|
|
15
|
+
return fn !== undefined ? fn.call(regexp, O) : new RegExp(regexp)[SEARCH](String(O));
|
|
16
|
+
},
|
|
17
|
+
// `RegExp.prototype[@@search]` method
|
|
18
|
+
// https://tc39.github.io/ecma262/#sec-regexp.prototype-@@search
|
|
19
|
+
function (regexp) {
|
|
20
|
+
var res = maybeCallNative($search, regexp, this);
|
|
21
|
+
if (res.done) return res.value;
|
|
22
|
+
var rx = anObject(regexp);
|
|
23
|
+
var S = String(this);
|
|
24
|
+
var previousLastIndex = rx.lastIndex;
|
|
25
|
+
if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;
|
|
26
|
+
var result = regExpExec(rx, S);
|
|
27
|
+
if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex;
|
|
28
|
+
return result === null ? -1 : result.index;
|
|
29
|
+
}
|
|
30
|
+
];
|
|
10
31
|
});
|