@@ -487,79 +487,62 @@ module.exports = {
487487 } ) ,
488488 utils . defineVueVisitor ( context , {
489489 /**
490- * e.g. `mapMutations({ add: 'increment' })`
491- * @param {Property } node
490+ * @param {CallExpression } node
492491 * @param {VueObjectData } vueData
493492 */
494- 'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ObjectExpression Property' (
495- node ,
496- vueData
497- ) {
498- const container = getVueComponentPropertiesContainer ( vueData . node )
499-
500- container . properties . push ( {
501- type : 'array' ,
502- name : utils . getStaticPropertyName ( node ) ,
503- groupName : 'methods' ,
504- node
505- } )
506- } ,
507-
508- /**
509- * e.g. `mapMutations(['add'])`
510- * @param {Literal } node
511- * @param {VueObjectData } vueData
512- */
513- 'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ArrayExpression Literal' (
514- node ,
515- vueData
516- ) {
517- const container = getVueComponentPropertiesContainer ( vueData . node )
518-
519- container . properties . push ( {
520- type : 'array' ,
521- name : utils . getStringLiteralValue ( node ) ,
522- groupName : 'methods' ,
523- node
524- } )
525- } ,
526-
527- /**
528- * e.g. `mapState({ count: state => state.todosCount })`
529- * @param {Property } node
530- * @param {VueObjectData } vueData
531- */
532- 'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ObjectExpression Property' (
533- node ,
534- vueData
535- ) {
536- const container = getVueComponentPropertiesContainer ( vueData . node )
537-
538- container . properties . push ( {
539- type : 'array' ,
540- name : utils . getStaticPropertyName ( node ) ,
541- groupName : 'computed' ,
542- node
543- } )
544- } ,
545-
546- /**
547- * e.g. `mapState(['count'])`
548- * @param {Literal } node
549- * @param {VueObjectData } vueData
550- */
551- 'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ArrayExpression Literal' (
552- node ,
553- vueData
554- ) {
555- const container = getVueComponentPropertiesContainer ( vueData . node )
493+ CallExpression ( node , vueData ) {
494+ if ( node . callee . type !== 'Identifier' ) return
495+ /** @type {'methods'|'computed'|null } */
496+ let groupName = null
497+ if ( / ^ m a p M u t a t i o n s | m a p A c t i o n s $ / u. test ( node . callee . name ) ) {
498+ groupName = 'methods'
499+ } else if ( / ^ m a p S t a t e | m a p G e t t e r s $ / u. test ( node . callee . name ) ) {
500+ groupName = 'computed'
501+ }
556502
557- container . properties . push ( {
558- type : 'array' ,
559- name : utils . getStringLiteralValue ( node ) ,
560- groupName : 'computed' ,
561- node
562- } )
503+ if ( ! groupName || node . arguments . length === 0 ) return
504+ const arg = node . arguments [ 0 ]
505+ if ( arg . type === 'ObjectExpression' ) {
506+ // e.g.
507+ // `mapMutations({ add: 'increment' })`
508+ // `mapState({ count: state => state.todosCount })`
509+ const container = getVueComponentPropertiesContainer ( vueData . node )
510+ for ( const prop of arg . properties ) {
511+ const name =
512+ prop . type === 'SpreadElement'
513+ ? null
514+ : utils . getStaticPropertyName ( prop )
515+ if ( name ) {
516+ container . properties . push ( {
517+ type : 'array' ,
518+ name,
519+ groupName,
520+ node : prop
521+ } )
522+ }
523+ }
524+ } else if ( arg . type === 'ArrayExpression' ) {
525+ // e.g. `mapMutations(['add'])`
526+ const container = getVueComponentPropertiesContainer ( vueData . node )
527+ for ( const element of arg . elements ) {
528+ if (
529+ ! element ||
530+ ( element . type !== 'Literal' &&
531+ element . type !== 'TemplateLiteral' )
532+ ) {
533+ continue
534+ }
535+ const name = utils . getStringLiteralValue ( element )
536+ if ( name ) {
537+ container . properties . push ( {
538+ type : 'array' ,
539+ name,
540+ groupName,
541+ node : element
542+ } )
543+ }
544+ }
545+ }
563546 } ,
564547
565548 onVueObjectEnter ( node , vueNode ) {
0 commit comments