@@ -453,5 +453,72 @@ module.exports = {
453453 cb ( node . arguments . slice ( - 1 ) [ 0 ] )
454454 }
455455 }
456+ } ,
457+
458+ /**
459+ * Return generator with all properties
460+ * @param {ASTNode } node Node to check
461+ * @param {string } groupName Name of parent group
462+ */
463+ * iterateProperties ( node , groups ) {
464+ const nodes = node . properties . filter ( p => p . type === 'Property' && groups . has ( this . getStaticPropertyName ( p . key ) ) )
465+ for ( const item of nodes ) {
466+ const name = this . getStaticPropertyName ( item . key )
467+ if ( item . value . type === 'ArrayExpression' ) {
468+ yield * this . iterateArrayExpression ( item . value , name )
469+ } else if ( item . value . type === 'ObjectExpression' ) {
470+ yield * this . iterateObjectExpression ( item . value , name )
471+ } else if ( item . value . type === 'FunctionExpression' ) {
472+ yield * this . iterateFunctionExpression ( item . value , name )
473+ }
474+ }
475+ } ,
476+
477+ /**
478+ * Return generator with all elements inside ArrayExpression
479+ * @param {ASTNode } node Node to check
480+ * @param {string } groupName Name of parent group
481+ */
482+ * iterateArrayExpression ( node , groupName ) {
483+ assert ( node . type === 'ArrayExpression' )
484+ for ( const item of node . elements ) {
485+ const name = this . getStaticPropertyName ( item )
486+ if ( name ) {
487+ const obj = { name, groupName, node : item }
488+ yield obj
489+ }
490+ }
491+ } ,
492+
493+ /**
494+ * Return generator with all elements inside ObjectExpression
495+ * @param {ASTNode } node Node to check
496+ * @param {string } groupName Name of parent group
497+ */
498+ * iterateObjectExpression ( node , groupName ) {
499+ assert ( node . type === 'ObjectExpression' )
500+ for ( const item of node . properties ) {
501+ const name = this . getStaticPropertyName ( item )
502+ if ( name ) {
503+ const obj = { name, groupName, node : item . key }
504+ yield obj
505+ }
506+ }
507+ } ,
508+
509+ /**
510+ * Return generator with all elements inside FunctionExpression
511+ * @param {ASTNode } node Node to check
512+ * @param {string } groupName Name of parent group
513+ */
514+ * iterateFunctionExpression ( node , groupName ) {
515+ assert ( node . type === 'FunctionExpression' )
516+ if ( node . body . type === 'BlockStatement' ) {
517+ for ( const item of node . body . body ) {
518+ if ( item . type === 'ReturnStatement' && item . argument . type === 'ObjectExpression' ) {
519+ yield * this . iterateObjectExpression ( item . argument , groupName )
520+ }
521+ }
522+ }
456523 }
457524}
0 commit comments