ObjectExpression.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  6. exports.default = extractValueFromObjectExpression;
  7. var _object = require('object.assign');
  8. var _object2 = _interopRequireDefault(_object);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * Extractor function for an ObjectExpression type value node.
  12. * An object expression is using {}.
  13. *
  14. * @returns - a representation of the object
  15. */
  16. function extractValueFromObjectExpression(value) {
  17. // eslint-disable-next-line global-require
  18. var getValue = require('./index.js').default;
  19. return value.properties.reduce(function (obj, property) {
  20. var object = _extends({}, obj);
  21. // Support types: SpreadProperty and ExperimentalSpreadProperty
  22. if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) {
  23. if (property.argument.type === 'ObjectExpression') {
  24. return (0, _object2.default)(object, extractValueFromObjectExpression(property.argument));
  25. }
  26. } else {
  27. object[getValue(property.key)] = getValue(property.value);
  28. }
  29. return object;
  30. }, {});
  31. }