| 63 | } |
| 64 | |
| 65 | function 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 | |
| 99 | export function parseSyntax(input: string): SyntaxParseResult { |
| 100 | const { ast, errors } = parseSyntaxToAst(input); |