1 | 'use strict';
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = getPropValue;
|
---|
7 | exports.getLiteralPropValue = getLiteralPropValue;
|
---|
8 |
|
---|
9 | var _values = require('./values');
|
---|
10 |
|
---|
11 | var _values2 = _interopRequireDefault(_values);
|
---|
12 |
|
---|
13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
14 |
|
---|
15 | var 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 | */
|
---|
40 | function 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 | */
|
---|
55 | function getLiteralPropValue(attribute) {
|
---|
56 | return extractValue(attribute, _values.getLiteralValue);
|
---|
57 | } |
---|