@@ -18,8 +18,9 @@ var Namespace = require("./namespace"),
1818 * @param {Object.<string,*> } [options] Declared options
1919 * @param {string } [comment] The comment for this enum
2020 * @param {Object.<string,string> } [comments] The value comments for this enum
21+ * @param {Object.<string,Object<string,*>>|undefined } [valuesOptions] The value options for this enum
2122 */
22- function Enum ( name , values , options , comment , comments ) {
23+ function Enum ( name , values , options , comment , comments , valuesOptions ) {
2324 ReflectionObject . call ( this , name , options ) ;
2425
2526 if ( values && typeof values !== "object" )
@@ -49,6 +50,12 @@ function Enum(name, values, options, comment, comments) {
4950 */
5051 this . comments = comments || { } ;
5152
53+ /**
54+ * Values options, if any
55+ * @type {Object<string, Object<string, *>>|undefined }
56+ */
57+ this . valuesOptions = valuesOptions ;
58+
5259 /**
5360 * Reserved ranges, if any.
5461 * @type {Array.<number[]|string> }
@@ -93,11 +100,12 @@ Enum.fromJSON = function fromJSON(name, json) {
93100Enum . prototype . toJSON = function toJSON ( toJSONOptions ) {
94101 var keepComments = toJSONOptions ? Boolean ( toJSONOptions . keepComments ) : false ;
95102 return util . toObject ( [
96- "options" , this . options ,
97- "values" , this . values ,
98- "reserved" , this . reserved && this . reserved . length ? this . reserved : undefined ,
99- "comment" , keepComments ? this . comment : undefined ,
100- "comments" , keepComments ? this . comments : undefined
103+ "options" , this . options ,
104+ "valuesOptions" , this . valuesOptions ,
105+ "values" , this . values ,
106+ "reserved" , this . reserved && this . reserved . length ? this . reserved : undefined ,
107+ "comment" , keepComments ? this . comment : undefined ,
108+ "comments" , keepComments ? this . comments : undefined
101109 ] ) ;
102110} ;
103111
@@ -106,11 +114,12 @@ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
106114 * @param {string } name Value name
107115 * @param {number } id Value id
108116 * @param {string } [comment] Comment, if any
117+ * @param {Object.<string, *>|undefined } [options] Options, if any
109118 * @returns {Enum } `this`
110119 * @throws {TypeError } If arguments are invalid
111120 * @throws {Error } If there is already a value with this name or id
112121 */
113- Enum . prototype . add = function add ( name , id , comment ) {
122+ Enum . prototype . add = function add ( name , id , comment , options ) {
114123 // utilized by the parser but not by .fromJSON
115124
116125 if ( ! util . isString ( name ) )
@@ -135,6 +144,12 @@ Enum.prototype.add = function add(name, id, comment) {
135144 } else
136145 this . valuesById [ this . values [ name ] = id ] = name ;
137146
147+ if ( options ) {
148+ if ( this . valuesOptions === undefined )
149+ this . valuesOptions = { } ;
150+ this . valuesOptions [ name ] = options || null ;
151+ }
152+
138153 this . comments [ name ] = comment || null ;
139154 return this ;
140155} ;
@@ -158,6 +173,8 @@ Enum.prototype.remove = function remove(name) {
158173 delete this . valuesById [ val ] ;
159174 delete this . values [ name ] ;
160175 delete this . comments [ name ] ;
176+ if ( this . valuesOptions )
177+ delete this . valuesOptions [ name ] ;
161178
162179 return this ;
163180} ;
0 commit comments