Skip to content

Commit 6870c2a

Browse files
committed
avoid some unnecessary global
1 parent 373e276 commit 6870c2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+175
-243
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## Changelog
22
##### Unreleased
3+
- Fixed the kind of error (`TypeError` instead of `Error`) on incorrect `exec` result in `RegExp.prototype.test` polyfill
34
- Fixed dependencies of `{ actual, full, features }/typed-array/at` entries
45
- Added Electron 20.0 compat data mapping
6+
- Refactoring
57

68
##### [3.22.7 - 2022.05.24](https://github.com/zloirock/core-js/releases/tag/v3.22.7)
79
- Added a workaround for V8 ~ Chrome 53 bug with non-writable prototype of some methods, [#1083](https://github.com/zloirock/core-js/issues/1083)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
var global = require('../internals/global');
21
var isCallable = require('../internals/is-callable');
32
var tryToString = require('../internals/try-to-string');
43

5-
var TypeError = global.TypeError;
4+
var $TypeError = TypeError;
65

76
// `Assert: IsCallable(argument) is true`
87
module.exports = function (argument) {
98
if (isCallable(argument)) return argument;
10-
throw TypeError(tryToString(argument) + ' is not a function');
9+
throw $TypeError(tryToString(argument) + ' is not a function');
1110
};
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
var global = require('../internals/global');
21
var isConstructor = require('../internals/is-constructor');
32
var tryToString = require('../internals/try-to-string');
43

5-
var TypeError = global.TypeError;
4+
var $TypeError = TypeError;
65

76
// `Assert: IsConstructor(argument) is true`
87
module.exports = function (argument) {
98
if (isConstructor(argument)) return argument;
10-
throw TypeError(tryToString(argument) + ' is not a constructor');
9+
throw $TypeError(tryToString(argument) + ' is not a constructor');
1110
};
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
var global = require('../internals/global');
21
var isCallable = require('../internals/is-callable');
32

4-
var String = global.String;
5-
var TypeError = global.TypeError;
3+
var $String = String;
4+
var $TypeError = TypeError;
65

76
module.exports = function (argument) {
87
if (typeof argument == 'object' || isCallable(argument)) return argument;
9-
throw TypeError("Can't set " + String(argument) + ' as a prototype');
8+
throw $TypeError("Can't set " + $String(argument) + ' as a prototype');
109
};
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
var global = require('../internals/global');
21
var isPrototypeOf = require('../internals/object-is-prototype-of');
32

4-
var TypeError = global.TypeError;
3+
var $TypeError = TypeError;
54

65
module.exports = function (it, Prototype) {
76
if (isPrototypeOf(Prototype, it)) return it;
8-
throw TypeError('Incorrect invocation');
7+
throw $TypeError('Incorrect invocation');
98
};
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
var global = require('../internals/global');
21
var isObject = require('../internals/is-object');
32

4-
var String = global.String;
5-
var TypeError = global.TypeError;
3+
var $String = String;
4+
var $TypeError = TypeError;
65

76
// `Assert: Type(argument) is Object`
87
module.exports = function (argument) {
98
if (isObject(argument)) return argument;
10-
throw TypeError(String(argument) + ' is not an object');
9+
throw $TypeError($String(argument) + ' is not an object');
1110
};

packages/core-js/internals/array-from.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
var global = require('../internals/global');
32
var bind = require('../internals/function-bind-context');
43
var call = require('../internals/function-call');
54
var toObject = require('../internals/to-object');
@@ -11,7 +10,7 @@ var createProperty = require('../internals/create-property');
1110
var getIterator = require('../internals/get-iterator');
1211
var getIteratorMethod = require('../internals/get-iterator-method');
1312

14-
var Array = global.Array;
13+
var $Array = Array;
1514

1615
// `Array.from` method implementation
1716
// https://tc39.es/ecma262/#sec-array.from
@@ -26,7 +25,7 @@ module.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undef
2625
var index = 0;
2726
var length, result, step, iterator, next, value;
2827
// if the target is not iterable or it's an array with the default iterator - use a simple case
29-
if (iteratorMethod && !(this == Array && isArrayIteratorMethod(iteratorMethod))) {
28+
if (iteratorMethod && !(this === $Array && isArrayIteratorMethod(iteratorMethod))) {
3029
iterator = getIterator(O, iteratorMethod);
3130
next = iterator.next;
3231
result = IS_CONSTRUCTOR ? new this() : [];
@@ -36,7 +35,7 @@ module.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undef
3635
}
3736
} else {
3837
length = lengthOfArrayLike(O);
39-
result = IS_CONSTRUCTOR ? new this(length) : Array(length);
38+
result = IS_CONSTRUCTOR ? new this(length) : $Array(length);
4039
for (;length > index; index++) {
4140
value = mapping ? mapfn(O[index], index) : O[index];
4241
createProperty(result, index, value);

packages/core-js/internals/array-group-by.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var global = require('../internals/global');
21
var bind = require('../internals/function-bind-context');
32
var uncurryThis = require('../internals/function-uncurry-this');
43
var IndexedObject = require('../internals/indexed-object');
@@ -8,7 +7,7 @@ var lengthOfArrayLike = require('../internals/length-of-array-like');
87
var objectCreate = require('../internals/object-create');
98
var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list');
109

11-
var Array = global.Array;
10+
var $Array = Array;
1211
var push = uncurryThis([].push);
1312

1413
module.exports = function ($this, callbackfn, that, specificConstructor) {
@@ -30,7 +29,7 @@ module.exports = function ($this, callbackfn, that, specificConstructor) {
3029
// TODO: Remove this block from `core-js@4`
3130
if (specificConstructor) {
3231
Constructor = specificConstructor(O);
33-
if (Constructor !== Array) {
32+
if (Constructor !== $Array) {
3433
for (key in target) target[key] = arrayFromConstructorAndList(Constructor, target[key]);
3534
}
3635
} return target;

packages/core-js/internals/array-reduce.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
var global = require('../internals/global');
21
var aCallable = require('../internals/a-callable');
32
var toObject = require('../internals/to-object');
43
var IndexedObject = require('../internals/indexed-object');
54
var lengthOfArrayLike = require('../internals/length-of-array-like');
65

7-
var TypeError = global.TypeError;
6+
var $TypeError = TypeError;
87

98
// `Array.prototype.{ reduce, reduceRight }` methods implementation
109
var createMethod = function (IS_RIGHT) {
@@ -23,7 +22,7 @@ var createMethod = function (IS_RIGHT) {
2322
}
2423
index += i;
2524
if (IS_RIGHT ? index < 0 : length <= index) {
26-
throw TypeError('Reduce of empty array with no initial value');
25+
throw $TypeError('Reduce of empty array with no initial value');
2726
}
2827
}
2928
for (;IS_RIGHT ? index >= 0 : length > index; index += i) if (index in self) {

packages/core-js/internals/array-slice-simple.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
var global = require('../internals/global');
21
var toAbsoluteIndex = require('../internals/to-absolute-index');
32
var lengthOfArrayLike = require('../internals/length-of-array-like');
43
var createProperty = require('../internals/create-property');
54

6-
var Array = global.Array;
5+
var $Array = Array;
76
var max = Math.max;
87

98
module.exports = function (O, start, end) {
109
var length = lengthOfArrayLike(O);
1110
var k = toAbsoluteIndex(start, length);
1211
var fin = toAbsoluteIndex(end === undefined ? length : end, length);
13-
var result = Array(max(fin - k, 0));
12+
var result = $Array(max(fin - k, 0));
1413
for (var n = 0; k < fin; k++, n++) createProperty(result, n, O[k]);
1514
result.length = n;
1615
return result;

0 commit comments

Comments
 (0)