@@ -56,18 +56,6 @@ function hasReferenceId(value, setupContext) {
56
56
)
57
57
}
58
58
59
- /**
60
- * Check if the given name matches emitReferenceIds variable name
61
- * @param {string } name
62
- * @param {Set<Identifier> } emitReferenceIds
63
- * @returns {boolean }
64
- */
65
- function isEmitVariableName ( name , emitReferenceIds ) {
66
- if ( emitReferenceIds . size === 0 ) return false
67
- const emitVariable = emitReferenceIds . values ( ) . next ( ) . value . name
68
- return emitVariable === name
69
- }
70
-
71
59
module . exports = {
72
60
meta : {
73
61
type : 'suggestion' ,
@@ -91,6 +79,7 @@ module.exports = {
91
79
/** @type {Map<ObjectExpression | Program, SetupContext> } */
92
80
const setupContexts = new Map ( )
93
81
const programNode = context . getSourceCode ( ) . ast
82
+ let emitParamName = ''
94
83
95
84
/**
96
85
* @param {CallExpression } node
@@ -204,14 +193,6 @@ module.exports = {
204
193
205
194
const { contextReferenceIds, emitReferenceIds } = setupContext
206
195
207
- // verify defineEmits variable in template
208
- if (
209
- callee . type === 'Identifier' &&
210
- isEmitVariableName ( callee . name , emitReferenceIds )
211
- ) {
212
- addEmitCall ( node )
213
- }
214
-
215
196
// verify setup(props,{emit}) {emit()}
216
197
addEmitCallByReference ( callee , emitReferenceIds , node )
217
198
if ( emit && emit . name === 'emit' ) {
@@ -229,8 +210,11 @@ module.exports = {
229
210
}
230
211
}
231
212
232
- // verify $emit() in template
233
- if ( callee . type === 'Identifier' && callee . name === '$emit' ) {
213
+ // verify $emit() and defineEmits variable in template
214
+ if (
215
+ callee . type === 'Identifier' &&
216
+ ( callee . name === '$emit' || callee . name === emitParamName )
217
+ ) {
234
218
addEmitCall ( node )
235
219
}
236
220
}
@@ -316,10 +300,15 @@ module.exports = {
316
300
}
317
301
318
302
const emitParam = node . parent . id
319
- const variable =
320
- emitParam . type === 'Identifier'
321
- ? findVariable ( utils . getScope ( context , emitParam ) , emitParam )
322
- : null
303
+ if ( emitParam . type !== 'Identifier' ) {
304
+ return
305
+ }
306
+
307
+ emitParamName = emitParam . name
308
+ const variable = findVariable (
309
+ utils . getScope ( context , emitParam ) ,
310
+ emitParam
311
+ )
323
312
if ( ! variable ) {
324
313
return
325
314
}
0 commit comments