@@ -311,7 +311,7 @@ ElementSerializer.prototype.build = function(element) {
311
311
var isGeneric = elementDescriptor . isGeneric ;
312
312
313
313
if ( isGeneric ) {
314
- otherAttrs = this . parseGeneric ( element ) ;
314
+ otherAttrs = this . parseGenericNsAttributes ( element ) ;
315
315
} else {
316
316
otherAttrs = this . parseNsAttributes ( element ) ;
317
317
}
@@ -325,7 +325,9 @@ ElementSerializer.prototype.build = function(element) {
325
325
// compute tag name
326
326
this . tagName = this . addTagName ( this . ns ) ;
327
327
328
- if ( ! isGeneric ) {
328
+ if ( isGeneric ) {
329
+ this . parseGenericContainments ( element ) ;
330
+ } else {
329
331
properties = getSerializableProperties ( element ) ;
330
332
331
333
this . parseAttributes ( filterAttributes ( properties ) ) ;
@@ -388,35 +390,29 @@ ElementSerializer.prototype.nsAttributeName = function(element) {
388
390
}
389
391
} ;
390
392
391
- ElementSerializer . prototype . parseGeneric = function ( element ) {
393
+ ElementSerializer . prototype . parseGenericNsAttributes = function ( element ) {
392
394
393
- var self = this ,
394
- body = this . body ;
395
-
396
- var attributes = [ ] ;
397
-
398
- forEach ( element , function ( val , key ) {
395
+ return Object . entries ( element ) . filter (
396
+ ( [ key , value ] ) => ! key . startsWith ( '$' ) && this . parseNsAttribute ( element , key , value )
397
+ ) . map (
398
+ ( [ key , value ] ) => ( { name : key , value : value } )
399
+ ) ;
400
+ } ;
399
401
400
- var nonNsAttr ;
402
+ ElementSerializer . prototype . parseGenericContainments = function ( element ) {
403
+ var body = element . $body ;
401
404
402
- if ( key === '$body' ) {
403
- body . push ( new BodySerializer ( ) . build ( { type : 'String' } , val ) ) ;
404
- } else
405
- if ( key === '$children' ) {
406
- forEach ( val , function ( child ) {
407
- body . push ( new ElementSerializer ( self ) . build ( child ) ) ;
408
- } ) ;
409
- } else
410
- if ( key . indexOf ( '$' ) !== 0 ) {
411
- nonNsAttr = self . parseNsAttribute ( element , key , val ) ;
405
+ if ( body ) {
406
+ this . body . push ( new BodySerializer ( ) . build ( { type : 'String' } , body ) ) ;
407
+ }
412
408
413
- if ( nonNsAttr ) {
414
- attributes . push ( { name : key , value : val } ) ;
415
- }
416
- }
417
- } ) ;
409
+ var children = element . $children ;
418
410
419
- return attributes ;
411
+ if ( children ) {
412
+ forEach ( children , child => {
413
+ this . body . push ( new ElementSerializer ( this ) . build ( child ) ) ;
414
+ } ) ;
415
+ }
420
416
} ;
421
417
422
418
ElementSerializer . prototype . parseNsAttribute = function ( element , name , value ) {
0 commit comments