Sha256: 8012ff28dc1b2b1f082ce35b0a6892c2e3db9d624f9a0675f59d9479ab421e01

Contents?: true

Size: 1.67 KB

Versions: 53

Compression:

Stored size: 1.67 KB

Contents

'use strict';

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

var _values = require('./values');

var _values2 = _interopRequireDefault(_values);

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

var extractValue = function extractValue(attribute, extractor) {
  if (attribute && attribute.type === 'JSXAttribute') {
    if (attribute.value === null) {
      // Null valued attributes imply truthiness.
      // For example: <div aria-hidden />
      // See: https://facebook.github.io/react/docs/jsx-in-depth.html#boolean-attributes
      return true;
    }

    return extractor(attribute.value);
  }

  return undefined;
};

/**
 * Returns the value of a given attribute.
 * Different types of attributes have their associated
 * values in different properties on the object.
 *
 * This function should return the most *closely* associated
 * value with the intention of the JSX.
 *
 * @param attribute - The JSXAttribute collected by AST parser.
 */
function getPropValue(attribute) {
  return extractValue(attribute, _values2.default);
}

/**
 * Returns the value of a given attribute.
 * Different types of attributes have their associated
 * values in different properties on the object.
 *
 * This function should return a value only if we can extract
 * a literal value from its attribute (i.e. values that have generic
 * types in JavaScript - strings, numbers, booleans, etc.)
 *
 * @param attribute - The JSXAttribute collected by AST parser.
 */
function getLiteralPropValue(attribute) {
  return extractValue(attribute, _values.getLiteralValue);
}

Version data entries

53 entries across 53 versions & 4 rubygems

Version Path
immosquare-cleaner-0.1.52 node_modules/jsx-ast-utils/lib/getPropValue.js
immosquare-cleaner-0.1.51 node_modules/jsx-ast-utils/lib/getPropValue.js
immosquare-cleaner-0.1.50 node_modules/jsx-ast-utils/lib/getPropValue.js
immosquare-cleaner-0.1.49 node_modules/jsx-ast-utils/lib/getPropValue.js
immosquare-cleaner-0.1.48 node_modules/jsx-ast-utils/lib/getPropValue.js
immosquare-cleaner-0.1.47 node_modules/jsx-ast-utils/lib/getPropValue.js
immosquare-cleaner-0.1.46 node_modules/jsx-ast-utils/lib/getPropValue.js
immosquare-cleaner-0.1.45 node_modules/jsx-ast-utils/lib/getPropValue.js
decidim-0.26.8 packages/eslint-config/node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-18.0.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.21.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.20.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.19.1 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.19.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.18.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.17.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.16.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.15.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.14.0 node_modules/jsx-ast-utils/lib/getPropValue.js
govuk_publishing_components-17.13.0 node_modules/jsx-ast-utils/lib/getPropValue.js