@@ -80,27 +80,48 @@ module.exports = async function (content, sourceMap) {
80
80
const ast = acorn . parse ( content , { sourceType : 'module' , ecmaVersion : 'latest' } )
81
81
acornWalk . simple ( ast , {
82
82
CallExpression ( node ) {
83
- if ( node . callee . name === '_c' ) {
83
+ let props
84
+
85
+ if (
86
+ // _c() or _vm._c()
87
+ node . callee . type === 'Identifier'
88
+ ? node . callee . name === '_c'
89
+ : ( node . callee . type === 'MemberExpression' &&
90
+ node . callee . object . name === '_vm' &&
91
+ node . callee . property . name === '_c' )
92
+ ) {
84
93
if ( node . arguments [ 0 ] . type === 'Literal' ) {
94
+ // _c('div')
85
95
matches . components . push ( [ node . arguments [ 0 ] . value , node . arguments [ 0 ] . start , node . arguments [ 0 ] . end ] )
86
96
}
97
+
87
98
if ( node . arguments . length >= 2 && node . arguments [ 1 ] . type === 'ObjectExpression' ) {
88
- const props = node . arguments [ 1 ] . properties
89
- props . forEach ( prop => {
90
- if ( prop . key . type === 'Identifier' && prop . key . name === 'directives' && prop . value . type === 'ArrayExpression' ) {
91
- prop . value . elements . forEach ( directive => {
92
- if ( directive . type === 'ObjectExpression' ) {
93
- directive . properties . forEach ( prop => {
94
- if ( prop . key . type === 'Identifier' && prop . key . name === 'name' ) {
95
- matches . directives . push ( [ prop . value . value , prop . start , prop . end ] )
96
- }
97
- } )
99
+ props = node . arguments [ 1 ] . properties
100
+ }
101
+ } else if (
102
+ // _vm._b() or _vm._g()
103
+ node . callee . type === 'MemberExpression' &&
104
+ node . callee . object . name === '_vm' &&
105
+ [ '_b' , '_g' ] . includes ( node . callee . property . name ) &&
106
+ node . arguments . length > 0 &&
107
+ node . arguments [ 0 ] . type === 'ObjectExpression'
108
+ ) {
109
+ props = node . arguments [ 0 ] . properties
110
+ }
111
+
112
+ props && props . forEach ( prop => {
113
+ if ( prop . key . type === 'Identifier' && prop . key . name === 'directives' && prop . value . type === 'ArrayExpression' ) {
114
+ prop . value . elements . forEach ( directive => {
115
+ if ( directive . type === 'ObjectExpression' ) {
116
+ directive . properties . forEach ( prop => {
117
+ if ( prop . key . type === 'Identifier' && prop . key . name === 'name' ) {
118
+ matches . directives . push ( [ prop . value . value , prop . start , prop . end ] )
98
119
}
99
120
} )
100
121
}
101
122
} )
102
123
}
103
- }
124
+ } )
104
125
}
105
126
} )
106
127
0 commit comments