Skip to content

Commit

Permalink
chore: Extract mbReadonly to wrap less.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh committed Dec 4, 2022
1 parent d5c289e commit 7dafd29
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,19 +766,18 @@ function generateOneofProperty(
): Code {
const { options } = ctx;
const fields = messageDesc.field.filter((field) => isWithinOneOf(field) && field.oneofIndex === oneofIndex);
const mbReadonly = maybeReadonly(options);
const unionType = joinCode(
fields.map((f) => {
let fieldName = maybeSnakeToCamel(f.name, options);
let typeName = toTypeName(ctx, messageDesc, f);
return code`{ ${maybeReadonly(options)}$case: '${fieldName}', ${maybeReadonly(
options
)}${fieldName}: ${typeName} }`;
return code`{ ${mbReadonly}$case: '${fieldName}', ${mbReadonly}${fieldName}: ${typeName} }`;
}),
{ on: " | " }
);

const name = maybeSnakeToCamel(messageDesc.oneofDecl[oneofIndex].name, options);
return code`${maybeReadonly(options)}${name}?: ${unionType},`;
return code`${mbReadonly}${name}?: ${unionType},`;

/*
// Ideally we'd put the comments for each oneof field next to the anonymous
Expand Down

0 comments on commit 7dafd29

Please sign in to comment.