ts-proto 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/main.js +6 -2
- package/package.json +1 -1
package/build/src/main.js
CHANGED
|
@@ -1971,6 +1971,7 @@ function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
|
|
|
1971
1971
|
toJSON(${messageDesc.field.length > 0 ? "message" : "_"}: ${fullName}): unknown {
|
|
1972
1972
|
const obj: any = {};
|
|
1973
1973
|
`);
|
|
1974
|
+
let currentIfTarget = "";
|
|
1974
1975
|
// then add a case for each field
|
|
1975
1976
|
messageDesc.field.forEach((field) => {
|
|
1976
1977
|
const fieldName = (0, utils_1.getFieldName)(field, options);
|
|
@@ -2120,10 +2121,11 @@ function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
|
|
|
2120
2121
|
: (0, utils_1.getPropertyAccessor)("message", (0, case_1.maybeSnakeToCamel)(messageDesc.oneofDecl[field.oneofIndex].name, options));
|
|
2121
2122
|
const valueName = (0, utils_1.oneofValueName)(fieldName, options);
|
|
2122
2123
|
chunks.push((0, ts_poet_1.code) `
|
|
2123
|
-
if (${oneofNameWithMessage}?.$case === '${fieldName}') {
|
|
2124
|
+
${currentIfTarget === oneofNameWithMessage ? "else " : ""}if (${oneofNameWithMessage}?.$case === '${fieldName}') {
|
|
2124
2125
|
${jsonProperty} = ${readSnippet(`${oneofNameWithMessage}.${valueName}`)};
|
|
2125
2126
|
}
|
|
2126
2127
|
`);
|
|
2128
|
+
currentIfTarget = oneofNameWithMessage;
|
|
2127
2129
|
}
|
|
2128
2130
|
else {
|
|
2129
2131
|
let emitDefaultValuesForJson = ctx.options.emitDefaultValues.includes("json-methods");
|
|
@@ -2176,6 +2178,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
2176
2178
|
createBase = (0, ts_poet_1.code) `Object.create(${createBase}) as ${fullName}`;
|
|
2177
2179
|
}
|
|
2178
2180
|
chunks.push((0, ts_poet_1.code) `const message = ${createBase}${maybeAsAny(options)};`);
|
|
2181
|
+
let currentIfTarget = "";
|
|
2179
2182
|
// add a check for each incoming field
|
|
2180
2183
|
messageDesc.field.forEach((field) => {
|
|
2181
2184
|
const fieldName = (0, utils_1.getFieldName)(field, options);
|
|
@@ -2298,7 +2301,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
2298
2301
|
const valueName = (0, utils_1.oneofValueName)(fieldName, options);
|
|
2299
2302
|
const v = readSnippet(`${oneofNameWithObject}.${valueName}`);
|
|
2300
2303
|
chunks.push((0, ts_poet_1.code) `
|
|
2301
|
-
if (
|
|
2304
|
+
${currentIfTarget === oneofNameWithObject ? "else " : ""}if (
|
|
2302
2305
|
${oneofNameWithObject}?.$case === '${fieldName}'
|
|
2303
2306
|
&& ${oneofNameWithObject}?.${valueName} !== undefined
|
|
2304
2307
|
&& ${oneofNameWithObject}?.${valueName} !== null
|
|
@@ -2306,6 +2309,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
2306
2309
|
${oneofNameWithMessage} = { $case: '${fieldName}', ${valueName}: ${v} };
|
|
2307
2310
|
}
|
|
2308
2311
|
`);
|
|
2312
|
+
currentIfTarget = oneofNameWithObject;
|
|
2309
2313
|
}
|
|
2310
2314
|
else if (readSnippet(`x`).toCodeString([]) == "x") {
|
|
2311
2315
|
// An optimized case of the else below that works when `readSnippet` returns the plain input
|