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

Function parse

packages/react/src/renderer/Parser/Parser.ts:8–22  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

6const parser = Parser.extend(jsx({ allowNamespaces: false }));
7
8export const parse = (source: string): SparseNode => {
9 const parsed = parser.parse(source, {
10 ecmaVersion: 2015,
11 });
12
13 if (parsed.body.length !== 1) {
14 throw new SyntaxError(`Expected a single root node, but got: ${parsed.body.length}`);
15 }
16
17 if (parsed.body[0].type !== 'ExpressionStatement') {
18 throw new SyntaxError(`Expected an expression statement, but got: ${parsed.body[0].type}`);
19 }
20
21 return parseNode(parsed.body[0].expression);
22};
23
24const parseNode = (node: any): SparseNode => {
25 const children = (node.children ?? []).map(parseNode).filter(Boolean);

Callers 1

Parser.spec.tsFile · 0.90

Calls 1

parseNodeFunction · 0.85

Tested by

no test coverage detected