Sha256: ceda5be8f50ef142360093ad8dea45beb09199b8f6b34cd64c88b56815e9a503

Contents?: true

Size: 1.22 KB

Versions: 43

Compression:

Stored size: 1.22 KB

Contents

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = elementType;
function resolveMemberExpressions() {
  var object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var property = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  if (object.type === 'JSXMemberExpression') {
    return resolveMemberExpressions(object.object, object.property) + '.' + property.name;
  }

  return object.name + '.' + property.name;
}

/**
 * Returns the tagName associated with a JSXElement.
 */
function elementType() {
  var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var name = node.name;


  if (!name) {
    throw new Error('The argument provided is not a JSXElement node.');
  }

  if (name.type === 'JSXMemberExpression') {
    var _name$object = name.object,
        object = _name$object === undefined ? {} : _name$object,
        _name$property = name.property,
        property = _name$property === undefined ? {} : _name$property;

    return resolveMemberExpressions(object, property);
  }

  if (name.type === 'JSXNamespacedName') {
    return name.namespace.name + ':' + name.name.name;
  }

  return node.name.name;
}

Version data entries

43 entries across 43 versions & 1 rubygems

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