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