Problem
didc bind --target mo emits snake_case type names, but the Motoko convention for types is PascalCase. This means generated bindings are not idiomatic Motoko and require a post-processing step to be usable in practice.
Example — current output:
public type canister_status_args = { canister_id : canister_id };
public type canister_status_result = { ... };
Expected idiomatic output:
public type CanisterStatusArgs = { canister_id : CanisterId };
public type CanisterStatusResult = { ... };
Note: record field labels and method names should stay snake_case — they are Candid identifiers, not Motoko identifiers. Only the type definition names and their references as types should be converted.
Context
This was discovered while maintaining caffeinelabs/mops-ic, the Motoko bindings package for the IC management canister. The initial generation in that repo was done with an undocumented post-processing step (snake→PascalCase); a follow-up PR (caffeinelabs/mops-ic#11) formalised this as scripts/pascal_types.py.
The Rust binding generator in didc already converts to PascalCase for struct/enum names (following Rust conventions). The Motoko generator should do the same.
Proposed fix
In rust/candid_parser/src/bindings/motoko.rs, convert type definition names (and their references) from snake_case to PascalCase when generating the public type declarations. Field labels (Label::Named) and method names should remain unchanged.
The conversion is straightforward: split on _, capitalise each word, join. The scripts/pascal_types.py in caffeinelabs/mops-ic#11 demonstrates the exact logic.
Additional note
didc 0.6.1 (current main) also fixes the float32 not supported in Motoko panic present in the released 0.5.4 binary — a release with both fixes would be very welcome.
Problem
didc bind --target moemitssnake_casetype names, but the Motoko convention for types isPascalCase. This means generated bindings are not idiomatic Motoko and require a post-processing step to be usable in practice.Example — current output:
Expected idiomatic output:
Note: record field labels and method names should stay
snake_case— they are Candid identifiers, not Motoko identifiers. Only the type definition names and their references as types should be converted.Context
This was discovered while maintaining
caffeinelabs/mops-ic, the Motoko bindings package for the IC management canister. The initial generation in that repo was done with an undocumented post-processing step (snake→PascalCase); a follow-up PR (caffeinelabs/mops-ic#11) formalised this asscripts/pascal_types.py.The Rust binding generator in
didcalready converts to PascalCase for struct/enum names (following Rust conventions). The Motoko generator should do the same.Proposed fix
In
rust/candid_parser/src/bindings/motoko.rs, convert type definition names (and their references) fromsnake_casetoPascalCasewhen generating thepublic typedeclarations. Field labels (Label::Named) and method names should remain unchanged.The conversion is straightforward: split on
_, capitalise each word, join. Thescripts/pascal_types.pyincaffeinelabs/mops-ic#11demonstrates the exact logic.Additional note
didc 0.6.1(currentmain) also fixes thefloat32 not supported in Motokopanic present in the released0.5.4binary — a release with both fixes would be very welcome.