feat(syntax): parse the apis container block

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-20 02:28:23 +05:30
co-authored by Claude Opus 5
parent d069f5ddd7
commit 87a00de5f3
6 changed files with 222 additions and 5 deletions
+18 -2
View File
@@ -1,5 +1,10 @@
import { WRN_RUNTIME_TARGETS } from "./spec.ts";
import { parseApiSections, hasRequestSection, type ApiSections } from "./api-sections.ts";
import {
parseApiSections,
parseApiEntries,
hasRequestSection,
type ApiSections,
} from "./api-sections.ts";
/**
* Recursive-descent parser for `.wrn`, producing a small AST.
@@ -142,7 +147,7 @@ export interface ApiBlock {
export type SeoBlock = Record<string, string>;
export type DataMode = "ssr" | "client";
export type DataMode = "ssr" | "client" | "any";
export interface DataApiBlock {
mode: DataMode;
@@ -845,6 +850,17 @@ export function parse(source: string): PageAst {
persist = parsePersist(lx.readBalancedBraces());
break;
}
case "apis": {
lx.next();
const body = lx.readBalancedBraces();
for (const entry of parseApiEntries(body)) {
if (dataApis.some((block) => block.name === entry.name)) {
throw new ParseError(`Duplicate api entry "${entry.name}" in apis block`);
}
dataApis.push(entry);
}
break;
}
default:
throw new ParseError(`Unknown page member '${kw.value}' at offset ${kw.pos}`);
}