Skip to content

Commit

Permalink
Other: Also support 'reserved' in enum descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Nov 27, 2017
1 parent 83477ca commit 843d0d5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ function Enum(name, values, options) {
*/
this.comments = {};

/**
* Reserved ranges, if any.
* @type {Array.<number[]|string>}
*/
this.reserved = undefined; // toJSON

// Note that values inherit valuesById on their prototype which makes them a TypeScript-
// compatible enum. This is used by pbts to write actual enum definitions that work for
// static and reflection code alike instead of emitting generic object definitions.
Expand All @@ -65,7 +71,9 @@ function Enum(name, values, options) {
* @throws {TypeError} If arguments are invalid
*/
Enum.fromJSON = function fromJSON(name, json) {
return new Enum(name, json.values, json.options);
var enm = new Enum(name, json.values, json.options);
enm.reserved = json.reserved;
return enm;
};

/**
Expand All @@ -74,8 +82,9 @@ Enum.fromJSON = function fromJSON(name, json) {
*/
Enum.prototype.toJSON = function toJSON() {
return util.toObject([
"options" , this.options,
"values" , this.values
"options" , this.options,
"values" , this.values,
"reserved" , this.reserved
]);
};

Expand Down

0 comments on commit 843d0d5

Please sign in to comment.