source: imaps-frontend/node_modules/jsx-ast-utils/lib/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: 1.3 KB
RevLine 
[d565449]1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = extractValueFromObjectExpression;
7
8var _object = require('object.assign');
9
10var _object2 = _interopRequireDefault(_object);
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14function _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 */
22function 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}
Note: See TracBrowser for help on using the repository browser.