Skip to content

Commit

Permalink
Use same key-value pair logic for readSnippet(x).toCodeString([]) !…
Browse files Browse the repository at this point in the history
…= "x" cases
  • Loading branch information
tresabhi committed Nov 9, 2024
1 parent 999346e commit 844da41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions integration/map-long-optional/test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2759,23 +2759,24 @@ function generateFromPartial(ctx: Context, fullName: string, messageDesc: Descri
${oneofNameWithMessage} = { $case: '${fieldName}', ${valueName}: ${v} };
}
`);
} else if (readSnippet(`x`).toCodeString([]) == "x") {
let fallback
} else {
let fallback;

if (keyValuePair) {
fallback = defaultValue(ctx, { ...field, label: FieldDescriptorProto_Label.LABEL_REQUIRED })
fallback = defaultValue(ctx, { ...field, label: FieldDescriptorProto_Label.LABEL_REQUIRED });
} else {
fallback = isWithinOneOf(field) || noDefaultValue ? "undefined" : defaultValue(ctx, field);
}

chunks.push(code`${messageProperty} = ${objectProperty} ?? ${fallback};`);
} else {
const fallback = isWithinOneOf(field) || noDefaultValue ? "undefined" : defaultValue(ctx, field);
chunks.push(code`
${messageProperty} = (${objectProperty} !== undefined && ${objectProperty} !== null)
? ${readSnippet(`${objectProperty}`)}
: ${fallback};
`);
if (readSnippet(`x`).toCodeString([]) == "x") {
chunks.push(code`${messageProperty} = ${objectProperty} ?? ${fallback};`);
} else {
chunks.push(code`
${messageProperty} = (${objectProperty} !== undefined && ${objectProperty} !== null)
? ${readSnippet(`${objectProperty}`)}
: ${fallback};
`);
}
}
});

Expand Down

0 comments on commit 844da41

Please sign in to comment.