@@ -7,6 +7,7 @@ var util = require("./util");
77
88var Root ; // cyclic
99
10+ // TODO: Replace with embedded proto.
1011var editions2023Defaults = { enum_type : "OPEN" , field_presence : "EXPLICIT" , json_format : "ALLOW" , message_encoding : "LENGTH_PREFIXED" , repeated_field_encoding : "PACKED" , utf8_validation : "VERIFY" } ;
1112var proto2Defaults = { enum_type : "CLOSED" , field_presence : "EXPLICIT" , json_format : "LEGACY_BEST_EFFORT" , message_encoding : "LENGTH_PREFIXED" , repeated_field_encoding : "EXPANDED" , utf8_validation : "NONE" } ;
1213var proto3Defaults = { enum_type : "OPEN" , field_presence : "IMPLICIT" , json_format : "ALLOW" , message_encoding : "LENGTH_PREFIXED" , repeated_field_encoding : "PACKED" , utf8_validation : "VERIFY" } ;
@@ -51,7 +52,7 @@ function ReflectionObject(name, options) {
5152 this . _features = { } ;
5253
5354 /**
54- * Resolved Features.
55+ * Unresolved Features.
5556 */
5657 this . _proto_features = null ;
5758
@@ -160,10 +161,10 @@ ReflectionObject.prototype.onRemove = function onRemove(parent) {
160161ReflectionObject . prototype . resolve = function resolve ( ) {
161162 if ( this . resolved )
162163 return this ;
163- if ( this . root instanceof Root || this . parent ) {
164+ if ( this instanceof Root || this . parent && this . parent . resolved )
164165 this . _resolveFeatures ( ) ;
166+ if ( this . root instanceof Root )
165167 this . resolved = true ;
166- }
167168 return this ;
168169} ;
169170
@@ -174,28 +175,24 @@ ReflectionObject.prototype.resolve = function resolve() {
174175ReflectionObject . prototype . _resolveFeatures = function _resolveFeatures ( ) {
175176 var defaults = { } ;
176177
177- if ( this . root . getOption ( "syntax" ) === "proto2" ) {
178- defaults = Object . assign ( { } , proto2Defaults ) ;
179- } else if ( this . root . getOption ( "syntax" ) === "proto3" ) {
180- defaults = Object . assign ( { } , proto3Defaults ) ;
181- } else if ( this . root . getOption ( "edition" ) === "2023" ) {
182- defaults = Object . assign ( { } , editions2023Defaults ) ;
178+ if ( this instanceof Root ) {
179+ if ( this . root . getOption ( "syntax" ) === "proto2" ) {
180+ defaults = Object . assign ( { } , proto2Defaults ) ;
181+ } else if ( this . root . getOption ( "syntax" ) === "proto3" ) {
182+ defaults = Object . assign ( { } , proto3Defaults ) ;
183+ } else if ( this . root . getOption ( "edition" ) === "2023" ) {
184+ defaults = Object . assign ( { } , editions2023Defaults ) ;
185+ }
183186 }
184187
185- if ( this . parent ) {
186- // This is an annoying workaround since we can't use the spread operator
187- // (Breaks the bundler and eslint)
188- // If we don't create a shallow copy, we end up also altering the parent's
189- // features
190- var parentFeaturesMerged = Object . assign ( defaults , this . parent . _proto_features ) ;
191- this . _features = Object . assign ( parentFeaturesMerged , this . _proto_features || { } ) ;
192- this . _proto_features = this . _features ;
193- this . parent . _resolveFeatures ( ) ;
194- } else {
188+ if ( this instanceof Root ) {
195189 this . _features = Object . assign ( defaults , this . _proto_features || { } ) ;
190+ } else if ( this . parent ) {
191+ var parentFeaturesCopy = Object . assign ( { } , this . parent . _features ) ;
192+ this . _features = Object . assign ( parentFeaturesCopy , this . _proto_features || { } ) ;
193+ } else {
194+ this . _features = Object . assign ( { } , this . _proto_features ) ;
196195 }
197- this . _proto_features = this . _features ;
198-
199196} ;
200197
201198/**
0 commit comments