MCPcopy Create free account
hub / github.com/composify-js/composify / parseNode

Function parseNode

packages/react/src/renderer/Parser/Parser.ts:24–58  ·  view source on GitHub ↗
(node: any)

Source from the content-addressed store, hash-verified

22};
23
24const parseNode = (node: any): SparseNode => {
25 const children = (node.children ?? []).map(parseNode).filter(Boolean);
26
27 switch (node.type) {
28 case 'JSXElement':
29 return {
30 __composify__: true,
31 type: node.openingElement.name.name,
32 props: node.openingElement.attributes.reduce((properties: Record<string, any>, attribute: any) => {
33 const key = attribute.name.name;
34 const value = parseAttribute(attribute.value);
35
36 if (value === undefined) {
37 return properties;
38 }
39
40 properties[key] = value;
41
42 return properties;
43 }, {}),
44 children,
45 };
46 case 'JSXFragment':
47 return {
48 __composify__: true,
49 type: 'Fragment',
50 props: {},
51 children,
52 };
53 case 'JSXText':
54 return node.value.trim();
55 default:
56 throw new SyntaxError(`${node.type} is not supported`);
57 }
58};
59
60const parseAttribute = (expression: any): any => {
61 if (expression === null) {

Callers 2

parseFunction · 0.85
parseAttributeFunction · 0.85

Calls 1

parseAttributeFunction · 0.85

Tested by

no test coverage detected