Skip to content

Commit 856af47

Browse files
Use field options in proto3 instead of adding an extra property
1 parent f2ed6e0 commit 856af47

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

cli/targets/static.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ function syntaxForType(type) {
371371

372372
function isOptional(field, syntax) {
373373

374-
return (syntax === "proto3") ? field.proto3Optional : field.optional;
374+
// In proto3, optional fields are explicit
375+
if (syntax === "proto3")
376+
return field.options != null && field.options["proto3_optional"] === true;
377+
378+
// In proto2, fields are explicitly optional if they are not part of a map, array or oneOf group
379+
return field.optional && !(field.partOf || field.repeated || field.map);
375380
}
376381

377382
function buildType(ref, type) {

src/field.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ function Field(name, id, type, rule, extend, options, comment) {
7878
if (extend !== undefined && !util.isString(extend))
7979
throw TypeError("extend must be a string");
8080

81-
/**
82-
* Explicit record of the proto3 optional rule
83-
* Needed to stop the proto3 optional semantics from getting lost
84-
* @type {boolean}
85-
*/
86-
this.proto3Optional = rule === "proto3_optional";
87-
8881
/**
8982
* Field rule, if any.
9083
* @type {string|undefined}

0 commit comments

Comments
 (0)