feat(syntax): parse the apis container block
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user