fix(compiler): bind protobuf TS consts across digit-camel divergence - #159
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.