MCPcopy
hub / github.com/antvis/Infographic / inferTemplateFromBareFirstLine

Function inferTemplateFromBareFirstLine

src/syntax/index.ts:65–97  ·  view source on GitHub ↗
(
  entries: Record<string, SyntaxNode>,
  warnings: SyntaxParseResult['warnings'],
)

Source from the content-addressed store, hash-verified

63}
64
65function inferTemplateFromBareFirstLine(
66 entries: Record<string, SyntaxNode>,
67 warnings: SyntaxParseResult['warnings'],
68) {
69 if ('infographic' in entries || 'template' in entries) {
70 return undefined;
71 }
72
73 const [firstEntry] = Object.entries(entries);
74 if (!firstEntry) return undefined;
75
76 const [key, node] = firstEntry;
77 if (ALLOWED_ROOT_KEYS.has(key) || node.kind !== 'object') {
78 return undefined;
79 }
80 if (node.value !== undefined || Object.keys(node.entries).length > 0) {
81 return undefined;
82 }
83
84 warnings.push({
85 path: 'template',
86 line: node.line,
87 code: 'implicit_template',
88 message:
89 'Inferred template from a bare first line. Prefix it with "infographic" or "template" to make the syntax explicit.',
90 raw: key,
91 });
92
93 return {
94 template: key,
95 inferredKey: key,
96 };
97}
98
99export function parseSyntax(input: string): SyntaxParseResult {
100 const { ast, errors } = parseSyntaxToAst(input);

Callers 1

parseSyntaxFunction · 0.85

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected