@@ -18,8 +18,9 @@ var Namespace = require("./namespace"),
18
18
* @param {Object.<string,*> } [options] Declared options
19
19
* @param {string } [comment] The comment for this enum
20
20
* @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
21
22
*/
22
- function Enum ( name , values , options , comment , comments ) {
23
+ function Enum ( name , values , options , comment , comments , valuesOptions ) {
23
24
ReflectionObject . call ( this , name , options ) ;
24
25
25
26
if ( values && typeof values !== "object" )
@@ -49,6 +50,12 @@ function Enum(name, values, options, comment, comments) {
49
50
*/
50
51
this . comments = comments || { } ;
51
52
53
+ /**
54
+ * Values options, if any
55
+ * @type {Object<string, Object<string, *>>|undefined }
56
+ */
57
+ this . valuesOptions = valuesOptions ;
58
+
52
59
/**
53
60
* Reserved ranges, if any.
54
61
* @type {Array.<number[]|string> }
@@ -93,11 +100,12 @@ Enum.fromJSON = function fromJSON(name, json) {
93
100
Enum . prototype . toJSON = function toJSON ( toJSONOptions ) {
94
101
var keepComments = toJSONOptions ? Boolean ( toJSONOptions . keepComments ) : false ;
95
102
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
101
109
] ) ;
102
110
} ;
103
111
@@ -106,11 +114,12 @@ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
106
114
* @param {string } name Value name
107
115
* @param {number } id Value id
108
116
* @param {string } [comment] Comment, if any
117
+ * @param {Object.<string, *>|undefined } [options] Options, if any
109
118
* @returns {Enum } `this`
110
119
* @throws {TypeError } If arguments are invalid
111
120
* @throws {Error } If there is already a value with this name or id
112
121
*/
113
- Enum . prototype . add = function add ( name , id , comment ) {
122
+ Enum . prototype . add = function add ( name , id , comment , options ) {
114
123
// utilized by the parser but not by .fromJSON
115
124
116
125
if ( ! util . isString ( name ) )
@@ -135,6 +144,12 @@ Enum.prototype.add = function add(name, id, comment) {
135
144
} else
136
145
this . valuesById [ this . values [ name ] = id ] = name ;
137
146
147
+ if ( options ) {
148
+ if ( this . valuesOptions === undefined )
149
+ this . valuesOptions = { } ;
150
+ this . valuesOptions [ name ] = options || null ;
151
+ }
152
+
138
153
this . comments [ name ] = comment || null ;
139
154
return this ;
140
155
} ;
@@ -158,6 +173,8 @@ Enum.prototype.remove = function remove(name) {
158
173
delete this . valuesById [ val ] ;
159
174
delete this . values [ name ] ;
160
175
delete this . comments [ name ] ;
176
+ if ( this . valuesOptions )
177
+ delete this . valuesOptions [ name ] ;
161
178
162
179
return this ;
163
180
} ;
0 commit comments