@@ -7,6 +7,10 @@ var util = require("./util");
7
7
8
8
var Root ; // cyclic
9
9
10
+ var editions2023Defaults = { enum_type : "OPEN" , field_presence : "EXPLICIT" , json_format : "ALLOW" , message_encoding : "LENGTH_PREFIXED" , repeated_field_encoding : "PACKED" , utf8_validation : "VERIFY" } ;
11
+ 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
+ var proto3Defaults = { enum_type : "OPEN" , field_presence : "IMPLICIT" , json_format : "ALLOW" , message_encoding : "LENGTH_PREFIXED" , repeated_field_encoding : "PACKED" , utf8_validation : "VERIFY" } ;
13
+
10
14
/**
11
15
* Constructs a new reflection object instance.
12
16
* @classdesc Base class of all reflection objects.
@@ -168,18 +172,30 @@ ReflectionObject.prototype.resolve = function resolve() {
168
172
* @returns {undefined }
169
173
*/
170
174
ReflectionObject . prototype . _resolveFeatures = function _resolveFeatures ( ) {
175
+ var defaults = { } ;
176
+
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 ) ;
183
+ }
184
+
171
185
if ( this . parent ) {
172
186
// This is an annoying workaround since we can't use the spread operator
173
187
// (Breaks the bundler and eslint)
174
188
// If we don't create a shallow copy, we end up also altering the parent's
175
189
// features
176
- var parentFeatures = Object . assign ( { } , this . parent . _proto_features ) ;
177
- this . _features = Object . assign ( parentFeatures , this . _proto_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 ;
178
193
this . parent . _resolveFeatures ( ) ;
179
194
} else {
180
- this . _features = Object . assign ( { } , this . _proto_features ) ;
195
+ this . _features = Object . assign ( defaults , this . _proto_features || { } ) ;
181
196
}
182
197
this . _proto_features = this . _features ;
198
+
183
199
} ;
184
200
185
201
/**
0 commit comments