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