@@ -7,6 +7,7 @@ var util = require("./util");
7
7
8
8
var Root ; // cyclic
9
9
10
+ // TODO: Replace with embedded proto.
10
11
var editions2023Defaults = { enum_type : "OPEN" , field_presence : "EXPLICIT" , json_format : "ALLOW" , message_encoding : "LENGTH_PREFIXED" , repeated_field_encoding : "PACKED" , utf8_validation : "VERIFY" } ;
11
12
var proto2Defaults = { enum_type : "CLOSED" , field_presence : "EXPLICIT" , json_format : "LEGACY_BEST_EFFORT" , message_encoding : "LENGTH_PREFIXED" , repeated_field_encoding : "EXPANDED" , utf8_validation : "NONE" } ;
12
13
var 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) {
51
52
this . _features = { } ;
52
53
53
54
/**
54
- * Resolved Features.
55
+ * Unresolved Features.
55
56
*/
56
57
this . _proto_features = null ;
57
58
@@ -160,10 +161,10 @@ ReflectionObject.prototype.onRemove = function onRemove(parent) {
160
161
ReflectionObject . prototype . resolve = function resolve ( ) {
161
162
if ( this . resolved )
162
163
return this ;
163
- if ( this . root instanceof Root || this . parent ) {
164
+ if ( this instanceof Root || this . parent && this . parent . resolved )
164
165
this . _resolveFeatures ( ) ;
166
+ if ( this . root instanceof Root )
165
167
this . resolved = true ;
166
- }
167
168
return this ;
168
169
} ;
169
170
@@ -174,28 +175,24 @@ ReflectionObject.prototype.resolve = function resolve() {
174
175
ReflectionObject . prototype . _resolveFeatures = function _resolveFeatures ( ) {
175
176
var defaults = { } ;
176
177
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
+ }
183
186
}
184
187
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 ) {
195
189
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 ) ;
196
195
}
197
- this . _proto_features = this . _features ;
198
-
199
196
} ;
200
197
201
198
/**
0 commit comments