implementation.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. // modified from https://github.com/es-shims/es6-shim
  3. var objectKeys = require('object-keys');
  4. var hasSymbols = require('has-symbols/shams')();
  5. var callBound = require('call-bind/callBound');
  6. var toObject = Object;
  7. var $push = callBound('Array.prototype.push');
  8. var $propIsEnumerable = callBound('Object.prototype.propertyIsEnumerable');
  9. var originalGetSymbols = hasSymbols ? Object.getOwnPropertySymbols : null;
  10. // eslint-disable-next-line no-unused-vars
  11. module.exports = function assign(target, source1) {
  12. if (target == null) { throw new TypeError('target must be an object'); }
  13. var to = toObject(target); // step 1
  14. if (arguments.length === 1) {
  15. return to; // step 2
  16. }
  17. for (var s = 1; s < arguments.length; ++s) {
  18. var from = toObject(arguments[s]); // step 3.a.i
  19. // step 3.a.ii:
  20. var keys = objectKeys(from);
  21. var getSymbols = hasSymbols && (Object.getOwnPropertySymbols || originalGetSymbols);
  22. if (getSymbols) {
  23. var syms = getSymbols(from);
  24. for (var j = 0; j < syms.length; ++j) {
  25. var key = syms[j];
  26. if ($propIsEnumerable(from, key)) {
  27. $push(keys, key);
  28. }
  29. }
  30. }
  31. // step 3.a.iii:
  32. for (var i = 0; i < keys.length; ++i) {
  33. var nextKey = keys[i];
  34. if ($propIsEnumerable(from, nextKey)) { // step 3.a.iii.2
  35. var propValue = from[nextKey]; // step 3.a.iii.2.a
  36. to[nextKey] = propValue; // step 3.a.iii.2.b
  37. }
  38. }
  39. }
  40. return to; // step 4
  41. };