Sha256: b5a6c5f1c537639d2949c9d570bf35d18563bc343cc0d2b06acaa559790576da

Contents?: true

Size: 1.55 KB

Versions: 25

Compression:

Stored size: 1.55 KB

Contents

'use strict';

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

var _Literal = require('./Literal');

var _Literal2 = _interopRequireDefault(_Literal);

var _JSXElement = require('./JSXElement');

var _JSXElement2 = _interopRequireDefault(_JSXElement);

var _expressions = require('./expressions');

var _expressions2 = _interopRequireDefault(_expressions);

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

// Composition map of types to their extractor functions.
var TYPES = {
  Literal: _Literal2.default,
  JSXElement: _JSXElement2.default,
  JSXExpressionContainer: _expressions2.default
};

// Composition map of types to their extractor functions to handle literals.
var LITERAL_TYPES = Object.assign({}, TYPES, {
  JSXElement: function JSXElement() {
    return null;
  },
  JSXExpressionContainer: _expressions.extractLiteral
});

/**
 * This function maps an AST value node
 * to its correct extractor function for its
 * given type.
 *
 * This will map correctly for *all* possible types.
 *
 * @param value - AST Value object on a JSX Attribute.
 */
function getValue(value) {
  return TYPES[value.type](value);
}

/**
 * This function maps an AST value node
 * to its correct extractor function for its
 * given type.
 *
 * This will map correctly for *some* possible types that map to literals.
 *
 * @param value - AST Value object on a JSX Attribute.
 */
function getLiteralValue(value) {
  return LITERAL_TYPES[value.type](value);
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
govuk_publishing_components-17.7.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.6.1 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.6.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.5.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.4.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.3.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.2.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.1.1 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.1.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-17.0.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.29.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.28.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.27.1 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.27.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.26.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.25.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.24.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.23.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.22.0 node_modules/jsx-ast-utils/lib/values/index.js
govuk_publishing_components-16.21.0 node_modules/jsx-ast-utils/lib/values/index.js