Skip to content

Commit

Permalink
Move Long case to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Oct 26, 2021
1 parent 323f0e4 commit 0161d83
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,22 +1207,20 @@ function generateFromPartial(ctx: Context, fullName: string, messageDesc: Descri
) {
message.${oneofName} = { $case: '${fieldName}', ${fieldName}: ${v} };
`);
} else if ((isLong(field) || isLongValueType(field)) && options.forceLong === LongOption.LONG) {
const v = readSnippet(`object.${fieldName}`);
const type = basicTypeName(ctx, field);
chunks.push(code`if (object.${fieldName} !== undefined && object.${fieldName} !== null) {`);
chunks.push(code`message.${fieldName} = ${v} as ${type};`);
chunks.push(code`} else {`);
const fallback = isWithinOneOf(field) ? 'undefined' : defaultValue(ctx, field);
chunks.push(code`message.${fieldName} = ${fallback}`);
} else {
if ((isLong(field) || isLongValueType(field)) && options.forceLong === LongOption.LONG) {
const v = readSnippet(`object.${fieldName}`);
const type = basicTypeName(ctx, field);
chunks.push(code`if (object.${fieldName} !== undefined && object.${fieldName} !== null) {`);
chunks.push(code`message.${fieldName} = ${v} as ${type};`);
chunks.push(code`} else {`);
const fallback = isWithinOneOf(field) ? 'undefined' : defaultValue(ctx, field);
chunks.push(code`message.${fieldName} = ${fallback}`);
} else {
chunks.push(code`if (object.${fieldName} !== undefined && object.${fieldName} !== null) {`);
chunks.push(code`message.${fieldName} = ${readSnippet(`object.${fieldName}`)};`);
chunks.push(code`} else {`);
const fallback = isWithinOneOf(field) ? 'undefined' : defaultValue(ctx, field);
chunks.push(code`message.${fieldName} = ${fallback}`);
}
chunks.push(code`if (object.${fieldName} !== undefined && object.${fieldName} !== null) {`);
chunks.push(code`message.${fieldName} = ${readSnippet(`object.${fieldName}`)};`);
chunks.push(code`} else {`);
const fallback = isWithinOneOf(field) ? 'undefined' : defaultValue(ctx, field);
chunks.push(code`message.${fieldName} = ${fallback}`);
}

chunks.push(code`}`);
Expand Down

0 comments on commit 0161d83

Please sign in to comment.