Skip to content

Commit f8ff8d8

Browse files
dmealingclaude
andcommitted
refactor(render+cli): simplify verify internals (code-review follow-up)
Behavior-preserving cleanups from the code-simplifier pass, all green: - render/src/verify.ts: `parse` arrow → function declaration (matches the other module-level helpers); drop a redundant `as Token[]` double-cast on section subtokens. - cli/src/commands/verify.ts: nested ternary → if/else chain for requiredSlots. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c36048b commit f8ff8d8

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

server/typescript/packages/cli/src/commands/verify.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ export async function verifyCommand(args: string[], cwd: string): Promise<number
7575

7676
const fieldTree = derivePayloadFieldTree(root, payloadRef);
7777
const slotsAttr = tmpl.ownAttr(TEMPLATE_ATTR_REQUIRED_SLOTS);
78-
const requiredSlots = Array.isArray(slotsAttr)
79-
? slotsAttr.filter((s): s is string => typeof s === "string")
80-
: typeof slotsAttr === "string"
81-
? [slotsAttr]
82-
: [];
78+
let requiredSlots: string[];
79+
if (Array.isArray(slotsAttr)) {
80+
requiredSlots = slotsAttr.filter((s): s is string => typeof s === "string");
81+
} else if (typeof slotsAttr === "string") {
82+
requiredSlots = [slotsAttr];
83+
} else {
84+
requiredSlots = [];
85+
}
8386

8487
const drift = verify(text, fieldTree, { provider, requiredSlots });
8588
checked++;

server/typescript/packages/render/src/verify.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ function resolve(stack: Stack, path: string): PayloadField | undefined {
7373
return current;
7474
}
7575

76-
const parse = (text: string): Token[] => Mustache.parse(text) as unknown as Token[];
76+
function parse(text: string): Token[] {
77+
return Mustache.parse(text) as unknown as Token[];
78+
}
7779

7880
/**
7981
* Walk a Mustache template's tokens against a payload field tree, returning a
@@ -108,7 +110,7 @@ export function verify(
108110
case "#": // {{#x}}…{{/x}}
109111
case "^": {
110112
// {{^x}}…{{/x}}
111-
const sub = (Array.isArray(tok[4]) ? (tok[4] as Token[]) : []) as Token[];
113+
const sub = Array.isArray(tok[4]) ? (tok[4] as Token[]) : [];
112114
if (value === ".") {
113115
walk(sub, stack, seen);
114116
break;

0 commit comments

Comments
 (0)