From e70543f246eb4b2711b276764c8e27423de72b4d Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Thu, 2 Jul 2026 21:14:50 -0400 Subject: [PATCH] format: add Name context type and guard to TS types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `name` context has a schema (program/context/name) but was never mirrored into the TypeScript types — no Context.Name interface, no isName guard, and it was absent from the Context union and isContext. Add Name (`{ name: string }`) and isName, mirroring isFrame, and wire them into the union and isContext (schema-canonical order: name first). Adds schema-guard test coverage for the name context. Unblocks upcoming consumers (name as invoke/return correlation id, #26) before compiler/UI start reading names. Behavior-preserving addition. --- packages/format/src/types/program/context.test.ts | 4 ++++ packages/format/src/types/program/context.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/format/src/types/program/context.test.ts b/packages/format/src/types/program/context.test.ts index a36e1e4c7..55a716181 100644 --- a/packages/format/src/types/program/context.test.ts +++ b/packages/format/src/types/program/context.test.ts @@ -6,6 +6,10 @@ testSchemaGuards("ethdebug/format/program/context", [ schema: "schema:ethdebug/format/program/context", guard: isContext, }, + { + schema: "schema:ethdebug/format/program/context/name", + guard: Context.isName, + }, { schema: "schema:ethdebug/format/program/context/code", guard: Context.isCode, diff --git a/packages/format/src/types/program/context.ts b/packages/format/src/types/program/context.ts index e943f1ec2..7c4e4ea4c 100644 --- a/packages/format/src/types/program/context.ts +++ b/packages/format/src/types/program/context.ts @@ -3,6 +3,7 @@ import { Type } from "#types/type"; import { Pointer, isPointer } from "#types/pointer"; export type Context = + | Context.Name | Context.Code | Context.Variables | Context.Remark @@ -16,6 +17,7 @@ export type Context = export const isContext = (value: unknown): value is Context => [ + Context.isName, Context.isCode, Context.isVariables, Context.isRemark, @@ -29,6 +31,16 @@ export const isContext = (value: unknown): value is Context => ].some((guard) => guard(value)); export namespace Context { + export interface Name { + name: string; + } + + export const isName = (value: unknown): value is Name => + typeof value === "object" && + !!value && + "name" in value && + typeof value.name === "string"; + export interface Code { code: Materials.SourceRange; }