Fixed: An enum's default value present as a string looks up using typeDefault, not defaultValue which is an array if repeated

This commit is contained in:
dcodeIO 2017-01-16 19:23:48 +01:00
parent b5daa27240
commit 08cda241a3
17 changed files with 41 additions and 53 deletions

View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.5.0 (c) 2016, Daniel Wirtz
* Compiled Mon, 16 Jan 2017 17:38:23 UTC
* Compiled Mon, 16 Jan 2017 18:22:03 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/
@ -1069,11 +1069,10 @@ converter.toObject = function toObject(mtype) {
("if(!o)")
("o={}")
("var d={}");
var repeatedFields = fields.filter(function(field) { return field.repeated; });
var repeatedFields = fields.filter(function(field) { return field.resolve().repeated; });
if (repeatedFields.length) { gen
("if(o.arrays||o.defaults){");
fields.forEach(function(field) {
if (field.resolve().repeated) gen
repeatedFields.forEach(function(field) { gen
("d%s=[]", field._prop);
}); gen
("}");
@ -1081,8 +1080,7 @@ converter.toObject = function toObject(mtype) {
var mapFields = fields.filter(function(field) { return field.map; });
if (mapFields.length) { gen
("if(o.objects||o.defaults){");
fields.forEach(function(field) {
if (field.map) gen
mapFields.forEach(function(field) { gen
("d%s={}", field._prop);
}); gen
("}");
@ -1090,9 +1088,7 @@ converter.toObject = function toObject(mtype) {
var otherFields = fields.filter(function(field) { return !(field.repeated || field.map); });
if (otherFields.length) { gen
("if(o.defaults){");
fields.forEach(function(field) {
if (field.repeated || field.map)
return;
otherFields.forEach(function(field) {
if (field.resolvedType instanceof Enum) gen
("d%s=o.enums===String?%j:%j", field._prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
else if (field.long) gen
@ -1753,7 +1749,7 @@ FieldPrototype.resolve = function resolve() {
if (this.options && this.options["default"] !== undefined) {
this.typeDefault = this.options["default"];
if (this.resolvedType instanceof Enum && typeof this.typeDefault === "string")
this.typeDefault = this.resolvedType.values[this.defaultValue];
this.typeDefault = this.resolvedType.values[this.typeDefault];
}
// convert to internal data type if necesssary

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

16
dist/protobuf.js vendored
View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.5.0 (c) 2016, Daniel Wirtz
* Compiled Mon, 16 Jan 2017 17:38:23 UTC
* Compiled Mon, 16 Jan 2017 18:22:03 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/
@ -1287,11 +1287,10 @@ converter.toObject = function toObject(mtype) {
("if(!o)")
("o={}")
("var d={}");
var repeatedFields = fields.filter(function(field) { return field.repeated; });
var repeatedFields = fields.filter(function(field) { return field.resolve().repeated; });
if (repeatedFields.length) { gen
("if(o.arrays||o.defaults){");
fields.forEach(function(field) {
if (field.resolve().repeated) gen
repeatedFields.forEach(function(field) { gen
("d%s=[]", field._prop);
}); gen
("}");
@ -1299,8 +1298,7 @@ converter.toObject = function toObject(mtype) {
var mapFields = fields.filter(function(field) { return field.map; });
if (mapFields.length) { gen
("if(o.objects||o.defaults){");
fields.forEach(function(field) {
if (field.map) gen
mapFields.forEach(function(field) { gen
("d%s={}", field._prop);
}); gen
("}");
@ -1308,9 +1306,7 @@ converter.toObject = function toObject(mtype) {
var otherFields = fields.filter(function(field) { return !(field.repeated || field.map); });
if (otherFields.length) { gen
("if(o.defaults){");
fields.forEach(function(field) {
if (field.repeated || field.map)
return;
otherFields.forEach(function(field) {
if (field.resolvedType instanceof Enum) gen
("d%s=o.enums===String?%j:%j", field._prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
else if (field.long) gen
@ -1971,7 +1967,7 @@ FieldPrototype.resolve = function resolve() {
if (this.options && this.options["default"] !== undefined) {
this.typeDefault = this.options["default"];
if (this.resolvedType instanceof Enum && typeof this.typeDefault === "string")
this.typeDefault = this.resolvedType.values[this.defaultValue];
this.typeDefault = this.resolvedType.values[this.typeDefault];
}
// convert to internal data type if necesssary

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.5.0 (c) 2016, Daniel Wirtz
* Compiled Mon, 16 Jan 2017 17:38:23 UTC
* Compiled Mon, 16 Jan 2017 18:22:03 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/

View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.5.0 (c) 2016, Daniel Wirtz
* Compiled Mon, 16 Jan 2017 17:38:23 UTC
* Compiled Mon, 16 Jan 2017 18:22:03 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/

Binary file not shown.

View File

@ -192,11 +192,10 @@ converter.toObject = function toObject(mtype) {
("if(!o)")
("o={}")
("var d={}");
var repeatedFields = fields.filter(function(field) { return field.repeated; });
var repeatedFields = fields.filter(function(field) { return field.resolve().repeated; });
if (repeatedFields.length) { gen
("if(o.arrays||o.defaults){");
fields.forEach(function(field) {
if (field.resolve().repeated) gen
repeatedFields.forEach(function(field) { gen
("d%s=[]", field._prop);
}); gen
("}");
@ -204,8 +203,7 @@ converter.toObject = function toObject(mtype) {
var mapFields = fields.filter(function(field) { return field.map; });
if (mapFields.length) { gen
("if(o.objects||o.defaults){");
fields.forEach(function(field) {
if (field.map) gen
mapFields.forEach(function(field) { gen
("d%s={}", field._prop);
}); gen
("}");
@ -213,9 +211,7 @@ converter.toObject = function toObject(mtype) {
var otherFields = fields.filter(function(field) { return !(field.repeated || field.map); });
if (otherFields.length) { gen
("if(o.defaults){");
fields.forEach(function(field) {
if (field.repeated || field.map)
return;
otherFields.forEach(function(field) {
if (field.resolvedType instanceof Enum) gen
("d%s=o.enums===String?%j:%j", field._prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
else if (field.long) gen

View File

@ -255,7 +255,7 @@ FieldPrototype.resolve = function resolve() {
if (this.options && this.options["default"] !== undefined) {
this.typeDefault = this.options["default"];
if (this.resolvedType instanceof Enum && typeof this.typeDefault === "string")
this.typeDefault = this.resolvedType.values[this.defaultValue];
this.typeDefault = this.resolvedType.values[this.typeDefault];
}
// convert to internal data type if necesssary

View File

@ -567,7 +567,7 @@ $root.vector_tile = (function() {
* Feature type.
* @type {number}
*/
Feature.prototype.type = undefined;
Feature.prototype.type = 0;
/**
* Feature geometry.
@ -796,7 +796,7 @@ $root.vector_tile = (function() {
object.id = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
} else
object.id = options.longs === String ? "0" : 0;
object.type = options.enums === String ? undefined : undefined;
object.type = options.enums === String ? "UNKNOWN" : 0;
}
if (message.hasOwnProperty("id") && message.id !== undefined && message.id !== null)
if (typeof message.id === "number")

View File

@ -2818,7 +2818,7 @@ $root.jspb = (function() {
* DefaultValues enumField.
* @type {number}
*/
DefaultValues.prototype.enumField = undefined;
DefaultValues.prototype.enumField = 13;
/**
* DefaultValues emptyField.
@ -3028,7 +3028,7 @@ $root.jspb = (function() {
object.intField = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
} else
object.intField = options.longs === String ? "11" : 11;
object.enumField = options.enums === String ? undefined : undefined;
object.enumField = options.enums === String ? "E1" : 13;
object.emptyField = "";
object.bytesField = options.bytes === String ? "moo" : [
109,
@ -10137,7 +10137,7 @@ $root.google = (function() {
* FileOptions optimizeFor.
* @type {number}
*/
FileOptions.prototype.optimizeFor = undefined;
FileOptions.prototype.optimizeFor = 1;
/**
* FileOptions goPackage.
@ -10487,7 +10487,7 @@ $root.google = (function() {
object.javaMultipleFiles = false;
object.javaGenerateEqualsAndHash = false;
object.javaStringCheckUtf8 = false;
object.optimizeFor = options.enums === String ? undefined : undefined;
object.optimizeFor = options.enums === String ? "SPEED" : 1;
object.goPackage = "";
object.ccGenericServices = false;
object.javaGenericServices = false;
@ -10848,7 +10848,7 @@ $root.google = (function() {
* FieldOptions ctype.
* @type {number}
*/
FieldOptions.prototype.ctype = undefined;
FieldOptions.prototype.ctype = 0;
/**
* FieldOptions packed.
@ -10860,7 +10860,7 @@ $root.google = (function() {
* FieldOptions jstype.
* @type {number}
*/
FieldOptions.prototype.jstype = undefined;
FieldOptions.prototype.jstype = 0;
/**
* FieldOptions lazy.
@ -11114,9 +11114,9 @@ $root.google = (function() {
if (options.arrays || options.defaults)
object.uninterpretedOption = [];
if (options.defaults) {
object.ctype = options.enums === String ? undefined : undefined;
object.ctype = options.enums === String ? "STRING" : 0;
object.packed = false;
object.jstype = options.enums === String ? undefined : undefined;
object.jstype = options.enums === String ? "JS_NORMAL" : 0;
object.lazy = false;
object.deprecated = false;
object.weak = false;
@ -12039,7 +12039,7 @@ $root.google = (function() {
* MethodOptions idempotencyLevel.
* @type {number}
*/
MethodOptions.prototype.idempotencyLevel = undefined;
MethodOptions.prototype.idempotencyLevel = 0;
/**
* MethodOptions uninterpretedOption.
@ -12217,7 +12217,7 @@ $root.google = (function() {
object.uninterpretedOption = [];
if (options.defaults) {
object.deprecated = false;
object.idempotencyLevel = options.enums === String ? undefined : undefined;
object.idempotencyLevel = options.enums === String ? "IDEMPOTENCY_UNKNOWN" : 0;
}
if (message.hasOwnProperty("deprecated") && message.deprecated !== undefined && message.deprecated !== null)
object.deprecated = message.deprecated;