Skip to content

refactor(ipc-codegen): keep the generator to erasable TypeScript - #25403

Open
charlielye wants to merge 1 commit into
nextfrom
cl/ipc-codegen-erasable-only
Open

refactor(ipc-codegen): keep the generator to erasable TypeScript#25403
charlielye wants to merge 1 commit into
nextfrom
cl/ipc-codegen-erasable-only

Conversation

@charlielye

Copy link
Copy Markdown
Contributor

Problem

ipc-codegen/src/generate.ts says:

* Zero npm dependencies — runs with Node.js 22+ via --experimental-strip-types.

It could not. Three parameter properties made Node reject the module at load:

$ node --experimental-strip-types ipc-codegen/src/generate.ts --lang rust ...
SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript parameter property is not supported in strip-only mode

generate.ts imports typescript_package_codegen.ts unconditionally, so this broke every --lang, not just ts.

Nothing noticed because all eleven call sites also pass --experimental-transform-types, which compiles parameter properties. The documented invocation was never exercised: the only test that runs strip-only is schema_visitor.test.ts, whose sole local import is schema_visitor.ts — it never reaches generate.ts.

Change

Expanded the three into an explicit field plus an assignment in the constructor body — what the transform emitted anyway:

-  constructor(private opts: CppCodegenOptions) {}
+  private opts: CppCodegenOptions;
+
+  constructor(opts: CppCodegenOptions) {
+    this.opts = opts;
+  }

That makes the source erasable, so --experimental-transform-types comes off all eleven call sites (3 CMakeLists, barretenberg/ts/bootstrap.sh, wsdb/bootstrap.sh, 5 echo_example bootstraps, the README). The generator now runs under the type stripping Node 23.6+ does by default.

--experimental-strip-types is kept: it is a no-op on the pinned Node (.nvmrc is v24.15.0) but is still required by the Node 22 the header mentions.

A fourth parameter property at typescript_package_codegen.ts:332 is inside a template literal — emitted code, not source — so it is untouched.

Verification

  • Generated output is byte-identical for all four languages, diffed against the previous invocation (--experimental-strip-types --experimental-transform-types) over bb_schema.json. This is a no-op for consumers.
  • All four --lang values generate with the transform flag gone.
  • ipc-codegen/test/schema_visitor.test.ts passes; echo_example/rust/bootstrap.sh (a real modified call site) generates fine.
  • Probed which constructs strip-only actually rejects, so the constraint is stated from measurement rather than memory: parameter properties, enum, const enum, and namespace are rejected; interfaces, type aliases, annotations, generics and import type are fine.

Guard

The failure mode is invisible while any caller passes the transform flag, so the property needs a test. ipc-codegen/scripts/strip_only_test.sh generates one of each --lang strip-only and is wired into test_cmds. Red/green checked — reintroducing a parameter property fails it:

SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript parameter property is not supported in strip-only mode
exit=1

The stronger guard would be erasableSyntaxOnly in a tsconfig, which fails at typecheck rather than at load. Not done here: ipc-codegen has no tsconfig.json or package.json (the "zero npm dependencies" claim is literal), and the repo pins TypeScript ^5.3.3 while that flag landed in 5.8.

🤖 Generated with Claude Code

https://claude.ai/code/session_016einpgfthfjLYGwCB3iQqD

generate.ts advertises "runs with Node.js 22+ via --experimental-strip-types",
but it could not: three parameter properties made Node reject it at module load
with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX, which takes out every --lang at once
rather than only the TypeScript backend. Nothing noticed because all eleven call
sites also pass --experimental-transform-types, which compiles those constructs,
so the documented invocation was never exercised -- the one test that does run
strip-only imports only schema_visitor.ts and never reaches generate.ts.

Expanding the three into an explicit field plus an assignment in the constructor
body -- what the transform emitted anyway -- makes the source erasable, so the
transform flag comes off all eleven call sites and the generator runs under the
type stripping that Node 23.6+ does by default. Generated output is byte-identical
for all four languages, checked against the previous invocation.

Keeping this property needs a test, since the failure mode is invisible while any
caller passes the transform flag: scripts/strip_only_test.sh generates one of each
--lang strip-only, and is wired into test_cmds. Reintroducing a parameter property
fails it with the ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX above.

--experimental-strip-types is kept even though it is a no-op on the pinned Node
(.nvmrc is v24.15.0): it is what the Node 22 the header mentions still needs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016einpgfthfjLYGwCB3iQqD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant