MCPcopy Index your code
hub / github.com/antvis/Infographic / parseSyntax

Function parseSyntax

src/syntax/index.ts:99–273  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

97}
98
99export function parseSyntax(input: string): SyntaxParseResult {
100 const { ast, errors } = parseSyntaxToAst(input);
101 const warnings: SyntaxParseResult['warnings'] = [];
102 const options: Partial<InfographicOptions> = {};
103
104 const mergedEntries = { ...ast.entries };
105 const inferredTemplate = inferTemplateFromBareFirstLine(
106 ast.entries,
107 warnings,
108 );
109 if (inferredTemplate) {
110 delete mergedEntries[inferredTemplate.inferredKey];
111 }
112
113 const infographicNode = ast.entries.infographic;
114 let templateFromInfographic: string | undefined;
115 if (infographicNode && infographicNode.kind === 'object') {
116 if (infographicNode.value) templateFromInfographic = infographicNode.value;
117 Object.entries(infographicNode.entries).forEach(([key, value]) => {
118 if (!(key in mergedEntries)) mergedEntries[key] = value;
119 });
120 }
121
122 Object.keys(mergedEntries).forEach((key) => {
123 if (!ALLOWED_ROOT_KEYS.has(key)) {
124 errors.push({
125 path: key,
126 line: (mergedEntries[key] as SyntaxNode).line,
127 code: 'unknown_key',
128 message: 'Unknown top-level key.',
129 raw: key,
130 });
131 }
132 });
133
134 const templateNode = mergedEntries.template as SyntaxNode | undefined;
135 const templateValue = resolveTemplate(templateNode, errors);
136 if (templateValue) options.template = templateValue;
137 if (!options.template && templateFromInfographic) {
138 options.template = templateFromInfographic;
139 }
140 if (!options.template && inferredTemplate) {
141 options.template = inferredTemplate.template;
142 }
143
144 const designNode = mergedEntries.design as SyntaxNode | undefined;
145 if (designNode) {
146 const design = mapWithSchema(designNode, DesignSchema, 'design', errors);
147 if (design) options.design = design;
148 }
149
150 const dataNode = mergedEntries.data as SyntaxNode | undefined;
151 if (dataNode) {
152 let relationsNode: SyntaxNode | undefined;
153 let dataNodeForMapping = dataNode;
154 if (dataNode.kind === 'object') {
155 const { relations, ...rest } = dataNode.entries;
156 relationsNode = relations;

Callers 3

parseSyntaxOptionsFunction · 0.90
EditorPanelFunction · 0.85

Calls 10

parseSyntaxToAstFunction · 0.90
mapWithSchemaFunction · 0.90
parseRelationsNodeFunction · 0.90
resolveTemplateFunction · 0.85
assignMissingNodeIdsFunction · 0.85
forEachMethod · 0.80
hasMethod · 0.80
getMethod · 0.80
normalizeItemsFunction · 0.70

Tested by

no test coverage detected