Skip to content

Commit 76e7cb2

Browse files
fix: fromObject should not initialize oneof members
1 parent 343e127 commit 76e7cb2

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

cli/targets/static.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,7 @@ function buildType(ref, type) {
394394
if (config.comments) {
395395
push("");
396396
var jsType = toJsType(field);
397-
if (field.optional && !field.map && !field.repeated && field.resolvedType instanceof Type ||
398-
field.options && field.options.proto3_optional)
397+
if (field.optional && !field.map && !field.repeated && field.resolvedType instanceof Type || field.partOf)
399398
jsType = jsType + "|null|undefined";
400399
pushComment([
401400
field.comment || type.name + " " + field.name + ".",
@@ -411,9 +410,8 @@ function buildType(ref, type) {
411410
push(escapeName(type.name) + ".prototype" + prop + " = $util.emptyArray;"); // overwritten in constructor
412411
else if (field.map)
413412
push(escapeName(type.name) + ".prototype" + prop + " = $util.emptyObject;"); // overwritten in constructor
414-
else if (field.options && field.options.proto3_optional) {
415-
push(escapeName(type.name) + ".prototype" + prop + " = null;"); // do not set default value for proto3 optional fields
416-
}
413+
else if (field.partOf)
414+
push(escapeName(type.name) + ".prototype" + prop + " = null;"); // do not set default value for oneof members
417415
else if (field.long)
418416
push(escapeName(type.name) + ".prototype" + prop + " = $util.Long ? $util.Long.fromBits("
419417
+ JSON.stringify(field.typeDefault.low) + ","

0 commit comments

Comments
 (0)