Skip to content

Commit f0491be

Browse files
committed
cleanup
1 parent f204288 commit f0491be

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

src/object.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ ReflectionObject.prototype.resolve = function resolve() {
152152
if (this.resolved)
153153
return this;
154154
this._resolveFeatures();
155-
// if (this.root instanceof Root)
156155
this.resolved = true;
157156
return this;
158157
};
@@ -188,17 +187,6 @@ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet)
188187
return this;
189188
};
190189

191-
/**
192-
* Sets a feature.
193-
* @param {string} name Feature name
194-
* @param {*} value Feature value
195-
* @returns {ReflectionObject} `this`
196-
*/
197-
ReflectionObject.prototype.setFeature = function setFeature(name, value) {
198-
(this.features || (this.features = {}))[name] = value;
199-
return this;
200-
};
201-
202190
/**
203191
* Sets a parsed option.
204192
* @param {string} name parsed Option name
@@ -238,7 +226,7 @@ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, valu
238226

239227
if (isFeature) {
240228
var features = parsedOptions.find(x => {return x.hasOwnProperty("features")});
241-
this._features = features.features ?? {};
229+
this._features = features.features || {};
242230
}
243231
return this;
244232
};

src/parse.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ function parse(source, root, options) {
635635
if (!this.parsedOptions) {
636636
this.parsedOptions = [];
637637
}
638+
var isFeature = /features/.test(name);
638639
var parsedOptions = this.parsedOptions;
639640
if (propName) {
640641
// If setting a sub property of an option then try to merge it
@@ -646,11 +647,11 @@ function parse(source, root, options) {
646647
// If we found an existing option - just merge the property value
647648
// (If it's a feature, will just write over)
648649
var newValue = opt[name];
649-
util.setProperty(newValue, propName, value);
650+
util.setProperty(newValue, propName, value, isFeature);
650651
} else {
651652
// otherwise, create a new option, set its property and add it to the list
652653
opt = {};
653-
opt[name] = util.setProperty({}, propName, value);
654+
opt[name] = util.setProperty({}, propName, value, isFeature);
654655
parsedOptions.push(opt);
655656
}
656657
} else {
@@ -660,10 +661,11 @@ function parse(source, root, options) {
660661
parsedOptions.push(newOpt);
661662
}
662663

663-
if (/features/.test(name)) {
664+
if (isFeature) {
664665
var features = parsedOptions.find(x => {return x.hasOwnProperty("features")});
665666
this._features = features.features || {};
666667
}
668+
return this;
667669
}
668670
ifBlock(dummy, function parseEnumValue_block(token) {
669671

@@ -723,6 +725,7 @@ function parse(source, root, options) {
723725
}
724726

725727
function parseOptionValue(parent, name) {
728+
// { a: "foo" b { c: "bar" } }
726729
if (skip("{", true)) {
727730
var objectResult = {};
728731

@@ -741,6 +744,9 @@ function parse(source, root, options) {
741744
skip(":", true);
742745

743746
if (peek() === "{") {
747+
// option (my_option) = {
748+
// repeated_value: [ "foo", "bar" ]
749+
// };
744750
value = parseOptionValue(parent, name + "." + token);
745751
} else if (peek() === "[") {
746752
value = [];

src/root.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,6 @@ Root.prototype.fetch = util.fetch;
7575
/* istanbul ignore next */
7676
function SYNC() {} // eslint-disable-line no-empty-function
7777

78-
/**
79-
Root --> Messages, Extensions, services, enums
80-
Messages --> Messages, Extensions, Fields, Enums, Oneofs
81-
Enums --> EnumValues
82-
Oneofs --> Fields
83-
Services --> Methods
84-
85-
Fields inherit features from oneof, not message
86-
Extensions inherit from the scope (file-level will inherit from the file, message-level will inherit from the message)
87-
*/
88-
8978
/**
9079
* Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
9180
* @param {string|string[]} filename Names of one or multiple files to load

0 commit comments

Comments
 (0)