Skip to content

fix(compiler): bind protobuf TS consts across digit-camel divergence - #159

Merged
paralin merged 1 commit into
masterfrom
fix/protobuf-ts-binding-v86fs
Aug 23, 2026
Merged

paralin merged 1 commit into
masterfrom
fix/protobuf-ts-binding-v86fs

Conversation

@paralin

@paralin paralin commented Aug 23, 2026

Copy link
Copy Markdown
Member

protoc-gen-go capitalizes the letter following a digit when it derives a Go struct name from a proto message, so a message spelled V86fs becomes the Go struct V86Fs. protobuf-es generated .pb.ts files keep the proto spelling and export const V86fs. The protobuf TypeScript binding kept a Go struct only when its safe identifier appeared exactly as an exported const in the .pb.ts file, so every message in packages such as db/unixfs/v86fs went unbound and their same-package oneof wrapper fields failed with goscript/protobuf-ts-binding:unresolved.

The binding now builds a case-insensitive index of the exported .pb.ts consts and falls back to it when the exact safe-identifier lookup misses. Exact matches are checked first and behave as before. The fallback binds only when exactly one exported const matches case-insensitively and no earlier struct has already claimed that const, and a bound struct references the actual exported spelling rather than assuming the Go-side one. Ambiguous case-collisions stay unbound and keep reporting the existing unresolved diagnostic, so matching remains fail-closed.

Adds TestProtobufTypeScriptBindingBindsDigitCamelCaseDivergence, which binds a Go V86Fs struct against a generated const V86fs while asserting that an exactly-matching struct still binds exactly.

protoc-gen-go capitalizes the letter following a digit when it derives
the Go struct name, so a proto message spelled V86fs becomes the Go
struct V86Fs. protobuf-es generated .pb.ts files keep the proto
spelling and export const V86fs. protobufTypeScriptBindingMessageNames
kept a struct only when its safe identifier appeared exactly as an
exported const, so every message in packages such as db/unixfs/v86fs
went unbound and same-package oneof wrapper fields failed with
goscript/protobuf-ts-binding:unresolved.

Build a case-insensitive index of the exported consts and fall back to
it when the exact safe-identifier lookup misses. The fallback binds
only when exactly one exported const matches and no earlier struct has
claimed it, so exact matches are unchanged and ambiguous pairs stay
unbound with the existing diagnostic. A bound struct now references the
actual exported const spelling instead of assuming the Go spelling.

Signed-off-by: Christian Stewart <[email protected]>
@paralin
paralin merged commit aa34256 into master Aug 23, 2026
9 checks passed
@paralin
paralin deleted the fix/protobuf-ts-binding-v86fs branch August 23, 2026 21:57
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