From 76e7cb24df61c5cfe257e6da20e98c515e141112 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Wed, 28 Apr 2021 00:47:41 -0700 Subject: [PATCH] fix: fromObject should not initialize oneof members --- cli/targets/static.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cli/targets/static.js b/cli/targets/static.js index ad4f7329b..a738f3585 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -394,8 +394,7 @@ function buildType(ref, type) { if (config.comments) { push(""); var jsType = toJsType(field); - if (field.optional && !field.map && !field.repeated && field.resolvedType instanceof Type || - field.options && field.options.proto3_optional) + if (field.optional && !field.map && !field.repeated && field.resolvedType instanceof Type || field.partOf) jsType = jsType + "|null|undefined"; pushComment([ field.comment || type.name + " " + field.name + ".", @@ -411,9 +410,8 @@ function buildType(ref, type) { push(escapeName(type.name) + ".prototype" + prop + " = $util.emptyArray;"); // overwritten in constructor else if (field.map) push(escapeName(type.name) + ".prototype" + prop + " = $util.emptyObject;"); // overwritten in constructor - else if (field.options && field.options.proto3_optional) { - push(escapeName(type.name) + ".prototype" + prop + " = null;"); // do not set default value for proto3 optional fields - } + else if (field.partOf) + push(escapeName(type.name) + ".prototype" + prop + " = null;"); // do not set default value for oneof members else if (field.long) push(escapeName(type.name) + ".prototype" + prop + " = $util.Long ? $util.Long.fromBits(" + JSON.stringify(field.typeDefault.low) + ","