@@ -442,67 +442,70 @@ module.exports = {
442
442
}
443
443
} ,
444
444
445
- iterateProperties ( node , groups , cb ) {
446
- node . properties
447
- . filter ( p => p . type === 'Property' && groups . has ( this . getStaticPropertyName ( p . key ) ) )
448
- . forEach ( node => {
449
- const name = this . getStaticPropertyName ( node . key )
450
- if ( node . value . type === 'ArrayExpression' ) {
451
- this . iterateArrayExpression ( node . value , name , cb )
452
- } else if ( node . value . type === 'ObjectExpression' ) {
453
- this . iterateObjectExpression ( node . value , name , cb )
454
- } else if ( node . value . type === 'FunctionExpression' ) {
455
- this . iterateFunctionExpression ( node . value , name , cb )
456
- }
457
- } )
445
+ /**
446
+ * Return generator with all properties
447
+ * @param {ASTNode } node Node to check
448
+ * @param {string } groupName Name of parent group
449
+ */
450
+ * iterateProperties ( node , groups ) {
451
+ const nodes = node . properties . filter ( p => p . type === 'Property' && groups . has ( this . getStaticPropertyName ( p . key ) ) )
452
+ for ( const item of nodes ) {
453
+ const name = this . getStaticPropertyName ( item . key )
454
+ if ( item . value . type === 'ArrayExpression' ) {
455
+ yield * this . iterateArrayExpression ( item . value , name )
456
+ } else if ( item . value . type === 'ObjectExpression' ) {
457
+ yield * this . iterateObjectExpression ( item . value , name )
458
+ } else if ( item . value . type === 'FunctionExpression' ) {
459
+ yield * this . iterateFunctionExpression ( item . value , name )
460
+ }
461
+ }
458
462
} ,
459
463
460
464
/**
461
- * Interate over all elements inside ArrayExpression
465
+ * Return generator with all elements inside ArrayExpression
462
466
* @param {ASTNode } node Node to check
463
467
* @param {string } groupName Name of parent group
464
- * @param {* } cb Callback function to iterate over nodes
465
468
*/
466
- iterateArrayExpression ( node , groupName , cb ) {
469
+ * iterateArrayExpression ( node , groupName ) {
467
470
assert ( node . type === 'ArrayExpression' )
468
- node . elements . forEach ( item => {
471
+ for ( const item of node . elements ) {
469
472
const name = this . getStaticPropertyName ( item )
470
473
if ( name ) {
471
- cb ( name , item , groupName )
474
+ const obj = { name, groupName, node : item }
475
+ yield obj
472
476
}
473
- } )
477
+ }
474
478
} ,
475
479
476
480
/**
477
- * Interate over all elements inside ObjectExpression
481
+ * Return generator with all elements inside ObjectExpression
478
482
* @param {ASTNode } node Node to check
479
483
* @param {string } groupName Name of parent group
480
- * @param {* } cb Callback function to iterate over nodes
481
484
*/
482
- iterateObjectExpression ( node , groupName , cb ) {
485
+ * iterateObjectExpression ( node , groupName ) {
483
486
assert ( node . type === 'ObjectExpression' )
484
- node . properties . forEach ( item => {
487
+ for ( const item of node . properties ) {
485
488
const name = this . getStaticPropertyName ( item )
486
489
if ( name ) {
487
- cb ( name , item . key , groupName )
490
+ const obj = { name, groupName, node : item . key }
491
+ yield obj
488
492
}
489
- } )
493
+ }
490
494
} ,
491
495
492
496
/**
493
- * Interate over all elements inside FunctionExpression
497
+ * Return generator with all elements inside FunctionExpression
494
498
* @param {ASTNode } node Node to check
495
499
* @param {string } groupName Name of parent group
496
- * @param {* } cb Callback function to iterate over nodes
497
500
*/
498
- iterateFunctionExpression ( node , groupName , cb ) {
501
+ * iterateFunctionExpression ( node , groupName ) {
499
502
assert ( node . type === 'FunctionExpression' )
500
503
if ( node . body . type === 'BlockStatement' ) {
501
- node . body . body . forEach ( item => {
504
+ for ( const item of node . body . body ) {
502
505
if ( item . type === 'ReturnStatement' && item . argument . type === 'ObjectExpression' ) {
503
- this . iterateObjectExpression ( item . argument , groupName , cb )
506
+ yield * this . iterateObjectExpression ( item . argument , groupName )
504
507
}
505
- } )
508
+ }
506
509
}
507
510
}
508
511
}
0 commit comments