-
Notifications
You must be signed in to change notification settings - Fork 121
Description
What problem does your feature solve?
When generating TypeScript bindings for Soroban contracts, certain valid Soroban identifiers produce invalid TypeScript/JavaScript code:
- Leading digits: A contract function named
123foogenerates an identifier that starts with a digit, which is invalid in JS/TS - Empty names: An empty name produces an empty identifier, which is invalid
- Reserved words: Names like
class,function,delete,export,import, etc. are valid Soroban identifiers but are reserved keywords in JavaScript/TypeScript
When a contract uses any of these as function names, struct names, field names, or enum variants, the generated TypeScript bindings will fail to compile.
What would you like to see?
The binding generator should produce syntactically valid TypeScript identifiers:
- Leading digits: Prefix with underscore (e.g.,
123foo→_123foo) - Empty names: Replace with a placeholder like
_or_empty - Reserved words: Append underscore suffix (e.g.,
class→class_) — this is a common convention in code generators
Note: The JS Stellar SDK also generates functions dynamically from contract specs. Any identifier mapping rules implemented here should be synchronized with the JS Stellar SDK to ensure consistent behavior. There are plans to move the TypeScript binding generation functionality from stellar-cli into the JS Stellar SDK. If that migration happens before this issue is addressed, this issue should be moved to that repository.
What alternatives are there?
- Fail at generation time: Reject contracts with problematic names and require users to rename them. This is more disruptive.
- Do nothing: Accept that some contracts will produce invalid bindings. Users would need to manually fix generated code.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status