@@ -7,6 +7,10 @@ var util = require("./util");
77
88var Root ; // cyclic
99
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+
1014/**
1115 * Constructs a new reflection object instance.
1216 * @classdesc Base class of all reflection objects.
@@ -168,18 +172,30 @@ ReflectionObject.prototype.resolve = function resolve() {
168172 * @returns {undefined }
169173 */
170174ReflectionObject . 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+
171185 if ( this . parent ) {
172186 // This is an annoying workaround since we can't use the spread operator
173187 // (Breaks the bundler and eslint)
174188 // If we don't create a shallow copy, we end up also altering the parent's
175189 // 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 ;
178193 this . parent . _resolveFeatures ( ) ;
179194 } else {
180- this . _features = Object . assign ( { } , this . _proto_features ) ;
195+ this . _features = Object . assign ( defaults , this . _proto_features || { } ) ;
181196 }
182197 this . _proto_features = this . _features ;
198+
183199} ;
184200
185201/**
0 commit comments