Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2: Add GeneratedFile.array #935

Merged
merged 2 commits into from
Jul 19, 2024
Merged

V2: Add GeneratedFile.array #935

merged 2 commits into from
Jul 19, 2024

Conversation

timostamm
Copy link
Member

@timostamm timostamm commented Jul 19, 2024

GeneratedFile already has the method string() to escape string literals. We already have an internal function for array literals. This promotes it to be a method on GeneratedFile as well.

import { GeneratedFile } from "@bufbuild/protoplugin";

declare f: GeneratedFile;

f.print("const arr = ", f.array([1, 2, 3]), ";");
// const arr = [1, 2, 3];

Signed-off-by: Timo Stamm <ts@timostamm.de>
Signed-off-by: Timo Stamm <ts@timostamm.de>
Comment on lines +86 to +90
* Escapes reserved words in ECMAScript and TypeScript identifiers, by appending
* a dollar sign.
*
* This function is intended for use with identifiers from Protobuf. The passed
* string must be a valid identifier (e.g. not start with a digit).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related, but I noticed the docs for the function safeIdentifier need clarification.

@timostamm timostamm requested a review from smaye81 July 19, 2024 11:44
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.

2 participants