UNPKG

2.38 kBJavaScriptView Raw
1'use strict';
2var DESCRIPTORS = require('../internals/descriptors');
3var uncurryThis = require('../internals/function-uncurry-this');
4var call = require('../internals/function-call');
5var fails = require('../internals/fails');
6var objectKeys = require('../internals/object-keys');
7var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
8var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
9var toObject = require('../internals/to-object');
10var IndexedObject = require('../internals/indexed-object');
11
12// eslint-disable-next-line es/no-object-assign -- safe
13var $assign = Object.assign;
14// eslint-disable-next-line es/no-object-defineproperty -- required for testing
15var defineProperty = Object.defineProperty;
16var concat = uncurryThis([].concat);
17
18// `Object.assign` method
19// https://tc39.es/ecma262/#sec-object.assign
20module.exports = !$assign || fails(function () {
21 // should have correct order of operations (Edge bug)
22 if (DESCRIPTORS && $assign({ b: 1 }, $assign(defineProperty({}, 'a', {
23 enumerable: true,
24 get: function () {
25 defineProperty(this, 'b', {
26 value: 3,
27 enumerable: false
28 });
29 }
30 }), { b: 2 })).b !== 1) return true;
31 // should work with symbols and should have deterministic property order (V8 bug)
32 var A = {};
33 var B = {};
34 // eslint-disable-next-line es/no-symbol -- safe
35 var symbol = Symbol('assign detection');
36 var alphabet = 'abcdefghijklmnopqrst';
37 A[symbol] = 7;
38 alphabet.split('').forEach(function (chr) { B[chr] = chr; });
39 return $assign({}, A)[symbol] !== 7 || objectKeys($assign({}, B)).join('') !== alphabet;
40}) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length`
41 var T = toObject(target);
42 var argumentsLength = arguments.length;
43 var index = 1;
44 var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
45 var propertyIsEnumerable = propertyIsEnumerableModule.f;
46 while (argumentsLength > index) {
47 var S = IndexedObject(arguments[index++]);
48 var keys = getOwnPropertySymbols ? concat(objectKeys(S), getOwnPropertySymbols(S)) : objectKeys(S);
49 var length = keys.length;
50 var j = 0;
51 var key;
52 while (length > j) {
53 key = keys[j++];
54 if (!DESCRIPTORS || call(propertyIsEnumerable, S, key)) T[key] = S[key];
55 }
56 } return T;
57} : $assign;