Sha256: 6adf5c769af8040465b8794cfd8bb9136d26539956fb1819523cafeeaab087fc

Contents?: true

Size: 1.13 KB

Versions: 18

Compression:

Stored size: 1.13 KB

Contents

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = extractValueFromObjectExpression;

var _object = require('object.assign');

var _object2 = _interopRequireDefault(_object);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Extractor function for an ObjectExpression type value node.
 * An object expression is using {}.
 *
 * @returns - a representation of the object
 */
function extractValueFromObjectExpression(value) {
  // eslint-disable-next-line global-require
  var getValue = require('./index.js').default;
  return value.properties.reduce(function (obj, property) {
    var object = (0, _object2.default)({}, obj);
    // Support types: SpreadProperty and ExperimentalSpreadProperty
    if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) {
      if (property.argument.type === 'ObjectExpression') {
        return (0, _object2.default)(object, extractValueFromObjectExpression(property.argument));
      }
    } else {
      object[getValue(property.key)] = getValue(property.value);
    }
    return object;
  }, {});
}

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.21.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.20.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.19.1 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.19.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.18.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.17.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.16.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.15.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.14.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.13.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.12.2 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.12.1 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.12.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.11.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.10.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.9.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js
govuk_publishing_components-17.8.0 node_modules/jsx-ast-utils/lib/values/expressions/ObjectExpression.js