source: imaps-frontend/node_modules/jsx-ast-utils/lib/getPropValue.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d565449]1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = getPropValue;
7exports.getLiteralPropValue = getLiteralPropValue;
8
9var _values = require('./values');
10
11var _values2 = _interopRequireDefault(_values);
12
13function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15var extractValue = function extractValue(attribute, extractor) {
16 if (attribute && attribute.type === 'JSXAttribute') {
17 if (attribute.value === null) {
18 // Null valued attributes imply truthiness.
19 // For example: <div aria-hidden />
20 // See: https://facebook.github.io/react/docs/jsx-in-depth.html#boolean-attributes
21 return true;
22 }
23
24 return extractor(attribute.value);
25 }
26
27 return undefined;
28};
29
30/**
31 * Returns the value of a given attribute.
32 * Different types of attributes have their associated
33 * values in different properties on the object.
34 *
35 * This function should return the most *closely* associated
36 * value with the intention of the JSX.
37 *
38 * @param attribute - The JSXAttribute collected by AST parser.
39 */
40function getPropValue(attribute) {
41 return extractValue(attribute, _values2.default);
42}
43
44/**
45 * Returns the value of a given attribute.
46 * Different types of attributes have their associated
47 * values in different properties on the object.
48 *
49 * This function should return a value only if we can extract
50 * a literal value from its attribute (i.e. values that have generic
51 * types in JavaScript - strings, numbers, booleans, etc.)
52 *
53 * @param attribute - The JSXAttribute collected by AST parser.
54 */
55function getLiteralPropValue(attribute) {
56 return extractValue(attribute, _values.getLiteralValue);
57}
Note: See TracBrowser for help on using the repository browser.