You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using protoc-gen-es with json_types=true option, if the value of json_name includes a hyphen(e.g. "x-id"), it causes errors in the generated Typescript or Javascript files.
We're already using string literals for names that aren't safe here, but clearly the logic is incomplete. It only uses string literals if the name starts with a digit or contains an @.
In JavaScript, identifiers are commonly made of alphanumeric characters, underscores (_), and dollar signs ($). Identifiers are not allowed to start with numbers.
For these common identifiers, it's most user-friendly to continue generating them as simple property names. I think it's reasonable to simply generate any other name with a string literal.
We should add test cases to packages/protobuf-test/extra/json_types.proto:
Describe the bug
When using
protoc-gen-es
withjson_types=true
option, if the value ofjson_name
includes a hyphen(e.g. "x-id"), it causes errors in the generated Typescript or Javascript files.To Reproduce
Additional context
The generated code should correctly handle the hyphen without causing syntax errors.
The text was updated successfully, but these errors were encountered: