source: imaps-frontend/node_modules/jsx-ast-utils/src/values/expressions/ObjectExpression.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 831 bytes
Line 
1import assign from 'object.assign';
2
3/**
4 * Extractor function for an ObjectExpression type value node.
5 * An object expression is using {}.
6 *
7 * @returns - a representation of the object
8 */
9export default function extractValueFromObjectExpression(value) {
10 // eslint-disable-next-line global-require
11 const getValue = require('.').default;
12 return value.properties.reduce((obj, property) => {
13 // Support types: SpreadProperty and ExperimentalSpreadProperty
14 if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) {
15 if (property.argument.type === 'ObjectExpression') {
16 return assign({}, obj, extractValueFromObjectExpression(property.argument));
17 }
18 } else {
19 return assign({}, obj, { [getValue(property.key)]: getValue(property.value) });
20 }
21 return obj;
22 }, {});
23}
Note: See TracBrowser for help on using the repository browser.