|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
831 bytes
|
| Line | |
|---|
| 1 | import 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 | */
|
|---|
| 9 | export 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.