1 | 'use strict';
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 |
|
---|
7 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
---|
8 |
|
---|
9 | exports.default = getValue;
|
---|
10 | exports.getLiteralValue = getLiteralValue;
|
---|
11 |
|
---|
12 | var _Literal = require('./Literal');
|
---|
13 |
|
---|
14 | var _Literal2 = _interopRequireDefault(_Literal);
|
---|
15 |
|
---|
16 | var _JSXElement = require('./JSXElement');
|
---|
17 |
|
---|
18 | var _JSXElement2 = _interopRequireDefault(_JSXElement);
|
---|
19 |
|
---|
20 | var _JSXText = require('./JSXText');
|
---|
21 |
|
---|
22 | var _JSXText2 = _interopRequireDefault(_JSXText);
|
---|
23 |
|
---|
24 | var _JSXFragment = require('./JSXFragment');
|
---|
25 |
|
---|
26 | var _JSXFragment2 = _interopRequireDefault(_JSXFragment);
|
---|
27 |
|
---|
28 | var _expressions = require('./expressions');
|
---|
29 |
|
---|
30 | var _expressions2 = _interopRequireDefault(_expressions);
|
---|
31 |
|
---|
32 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
33 |
|
---|
34 | // Composition map of types to their extractor functions.
|
---|
35 | var TYPES = {
|
---|
36 | Literal: _Literal2.default,
|
---|
37 | JSXElement: _JSXElement2.default,
|
---|
38 | JSXExpressionContainer: _expressions2.default,
|
---|
39 | JSXText: _JSXText2.default,
|
---|
40 | JSXFragment: _JSXFragment2.default
|
---|
41 | };
|
---|
42 |
|
---|
43 | // Composition map of types to their extractor functions to handle literals.
|
---|
44 | var LITERAL_TYPES = _extends({}, TYPES, {
|
---|
45 | JSXElement: function JSXElement() {
|
---|
46 | return null;
|
---|
47 | },
|
---|
48 | JSXExpressionContainer: _expressions.extractLiteral
|
---|
49 | });
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * This function maps an AST value node
|
---|
53 | * to its correct extractor function for its
|
---|
54 | * given type.
|
---|
55 | *
|
---|
56 | * This will map correctly for *all* possible types.
|
---|
57 | *
|
---|
58 | * @param value - AST Value object on a JSX Attribute.
|
---|
59 | */
|
---|
60 | function getValue(value) {
|
---|
61 | if (!TYPES[value.type]) console.log(value.type);
|
---|
62 | return TYPES[value.type](value);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * This function maps an AST value node
|
---|
67 | * to its correct extractor function for its
|
---|
68 | * given type.
|
---|
69 | *
|
---|
70 | * This will map correctly for *some* possible types that map to literals.
|
---|
71 | *
|
---|
72 | * @param value - AST Value object on a JSX Attribute.
|
---|
73 | */
|
---|
74 | function getLiteralValue(value) {
|
---|
75 | return LITERAL_TYPES[value.type](value);
|
---|
76 | } |
---|