source: imaps-frontend/node_modules/jsx-ast-utils/lib/values/index.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.1 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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
9exports.default = getValue;
10exports.getLiteralValue = getLiteralValue;
11
12var _Literal = require('./Literal');
13
14var _Literal2 = _interopRequireDefault(_Literal);
15
16var _JSXElement = require('./JSXElement');
17
18var _JSXElement2 = _interopRequireDefault(_JSXElement);
19
20var _JSXText = require('./JSXText');
21
22var _JSXText2 = _interopRequireDefault(_JSXText);
23
24var _JSXFragment = require('./JSXFragment');
25
26var _JSXFragment2 = _interopRequireDefault(_JSXFragment);
27
28var _expressions = require('./expressions');
29
30var _expressions2 = _interopRequireDefault(_expressions);
31
32function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
34// Composition map of types to their extractor functions.
35var 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.
44var 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 */
60function 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 */
74function getLiteralValue(value) {
75 return LITERAL_TYPES[value.type](value);
76}
Note: See TracBrowser for help on using the repository browser.