Skip to content

Commit b7ccbbd

Browse files
authored
fix(no-unused-emit-declarations): error in render functions (#2388)
1 parent ac73565 commit b7ccbbd

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/rules/no-unused-emit-declarations.js

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function hasReferenceId(value, setupContext) {
6363
* @returns {boolean}
6464
*/
6565
function isEmitVariableName(name, emitReferenceIds) {
66+
if (emitReferenceIds.size === 0) return false
6667
const emitVariable = emitReferenceIds.values().next().value.name
6768
return emitVariable === name
6869
}

tests/lib/rules/no-unused-emit-declarations.js

+34
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,19 @@ tester.run('no-unused-emit-declarations', rule, {
369369
const m = defineModel('foo')
370370
</script>
371371
`
372+
},
373+
{
374+
filename: 'test.vue',
375+
code: `
376+
<script>
377+
export default {
378+
emits: ['foo'],
379+
setup(_, ctx) {
380+
return () => h('button', { onClick: () => ctx.emit('foo') })
381+
}
382+
}
383+
</script>
384+
`
372385
}
373386
],
374387
invalid: [
@@ -750,6 +763,27 @@ tester.run('no-unused-emit-declarations', rule, {
750763
line: 3
751764
}
752765
]
766+
},
767+
{
768+
filename: 'test.vue',
769+
code: `
770+
<script>
771+
export default {
772+
emits: ['foo'],
773+
setup(_, ctx) {
774+
return () => h('button')
775+
}
776+
}
777+
</script>
778+
`,
779+
errors: [
780+
{
781+
messageId: 'unused',
782+
line: 4,
783+
column: 19,
784+
endColumn: 24
785+
}
786+
]
753787
}
754788
]
755789
})

0 commit comments

Comments
 (0)