@@ -86,6 +86,7 @@ function findFirstSample(e) {
8686const isPrimitive = e => ( e instanceof StringElement ) || ( e instanceof NumberElement ) || ( e instanceof BooleanElement ) ;
8787const isEnumElement = e => e instanceof EnumElement ;
8888const isArrayElement = e => e instanceof ArrayElement ;
89+ const isObjectElement = e => e instanceof ObjectElement ;
8990
9091const hasSample = e => findFirstSample ( e ) !== null ;
9192const hasDefault = e => findDefault ( e ) !== null ;
@@ -94,6 +95,9 @@ const hasValue = R.anyPass([hasContent, hasSample, hasDefault]);
9495const hasNoValue = R . complement ( hasValue ) ;
9596const isNoValuePrimitive = R . both ( isPrimitive , hasNoValue ) ;
9697const isNonEmptyArrayElement = e => isArrayElement ( e ) && e . content && ! e . isEmpty ;
98+ const isEmptyArray = e => isArrayElement ( e ) && e . content . every ( isNoValuePrimitive ) ;
99+ const isObjectWithUndefinedValues = e => isObjectElement ( e )
100+ && e . content . every ( prop => prop . value === undefined || prop . value . content === undefined ) ;
97101
98102
99103function trivialValue ( e ) {
@@ -123,7 +127,7 @@ function mapValue(e, options, f, elements) {
123127
124128 const opts = updateTypeAttributes ( e , options ) ;
125129
126- if ( e . content && ! ( isArrayElement ( e ) && e . content . every ( isNoValuePrimitive ) ) ) {
130+ if ( e . content && ! isEmptyArray ( e ) && ! isObjectWithUndefinedValues ( e ) ) {
127131 const result = f ( e , opts , elements , 'content' ) ;
128132
129133 if ( undefined !== result ) {
@@ -226,7 +230,7 @@ function reduceValue(e, options, elements) {
226230 return mapValue ( e . content , inheritFlags ( opts ) , reduceValue , elements ) ;
227231 }
228232
229- if ( e instanceof ObjectElement ) {
233+ if ( isObjectElement ( e ) ) {
230234 let result = { } ;
231235
232236 const isFixed = isFlag ( FIXED_FLAG , opts ) ;
0 commit comments