Permalink
Browse files

New: Added `oneofs: true` to ConversionOptions, see #710

  • Loading branch information...
dcodeIO committed Mar 20, 2017
1 parent 228c882 commit fe93d436b430d01b563318bff591e0dd408c06a4
Showing with 5 additions and 1 deletion.
  1. +4 −1 src/converter.js
  2. +1 −0 src/type.js
@@ -193,7 +193,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
*/
converter.toObject = function toObject(mtype) {
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
var fields = mtype.fieldsArray;
var fields = mtype.fieldsArray.sort(util.compareFieldsById);
if (!fields.length)
return util.codegen()("return {}");
var gen = util.codegen("m", "o")
@@ -265,6 +265,9 @@ converter.toObject = function toObject(mtype) {
("}");
} else
genValuePartial_toObject(gen, field, i, prop);
if (field.partOf) gen
("if(o.oneofs)")
("d%s=%j", util.safeProp(field.partOf.name), field.name);
gen
("}");
}
@@ -484,6 +484,7 @@ Type.prototype.from = Type.prototype.fromObject;
* @property {boolean} [defaults=false] Also sets default values on the resulting object
* @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
* @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`
* @property {boolean} [oneofs=false] Includes virtual oneof properties set to the present field's name, if any
*/
/**

0 comments on commit fe93d43

Please sign in to comment.