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.2 KB
|
Line | |
---|
1 | import Literal from './Literal';
|
---|
2 | import JSXElement from './JSXElement';
|
---|
3 | import JSXText from './JSXText';
|
---|
4 | import JSXFragment from './JSXFragment';
|
---|
5 | import JSXExpressionContainer, { extractLiteral } from './expressions';
|
---|
6 |
|
---|
7 | // Composition map of types to their extractor functions.
|
---|
8 | const 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.
|
---|
17 | const 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 | */
|
---|
32 | export 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 | */
|
---|
46 | export function getLiteralValue(value) {
|
---|
47 | return LITERAL_TYPES[value.type](value);
|
---|
48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.