source: imaps-frontend/node_modules/jsx-ast-utils/src/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: 1.2 KB
RevLine 
[d565449]1import Literal from './Literal';
2import JSXElement from './JSXElement';
3import JSXText from './JSXText';
4import JSXFragment from './JSXFragment';
5import JSXExpressionContainer, { extractLiteral } from './expressions';
6
7// Composition map of types to their extractor functions.
8const TYPES = {
9 Literal,
10 JSXElement,
11 JSXExpressionContainer,
12 JSXText,
13 JSXFragment,
14};
15
16// Composition map of types to their extractor functions to handle literals.
17const LITERAL_TYPES = {
18 ...TYPES,
19 JSXElement: () => null,
20 JSXExpressionContainer: extractLiteral,
21};
22
23/**
24 * This function maps an AST value node
25 * to its correct extractor function for its
26 * given type.
27 *
28 * This will map correctly for *all* possible types.
29 *
30 * @param value - AST Value object on a JSX Attribute.
31 */
32export default function getValue(value) {
33 if (!TYPES[value.type]) console.log(value.type);
34 return TYPES[value.type](value);
35}
36
37/**
38 * This function maps an AST value node
39 * to its correct extractor function for its
40 * given type.
41 *
42 * This will map correctly for *some* possible types that map to literals.
43 *
44 * @param value - AST Value object on a JSX Attribute.
45 */
46export function getLiteralValue(value) {
47 return LITERAL_TYPES[value.type](value);
48}
Note: See TracBrowser for help on using the repository browser.