From b7ccbbd40ec4646a58eef4133913669e7eac833f Mon Sep 17 00:00:00 2001 From: ntnyq Date: Wed, 31 Jan 2024 18:33:56 +0800 Subject: [PATCH] fix(no-unused-emit-declarations): error in render functions (#2388) --- lib/rules/no-unused-emit-declarations.js | 1 + .../lib/rules/no-unused-emit-declarations.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/rules/no-unused-emit-declarations.js b/lib/rules/no-unused-emit-declarations.js index 1a88d2417..146438935 100644 --- a/lib/rules/no-unused-emit-declarations.js +++ b/lib/rules/no-unused-emit-declarations.js @@ -63,6 +63,7 @@ function hasReferenceId(value, setupContext) { * @returns {boolean} */ function isEmitVariableName(name, emitReferenceIds) { + if (emitReferenceIds.size === 0) return false const emitVariable = emitReferenceIds.values().next().value.name return emitVariable === name } diff --git a/tests/lib/rules/no-unused-emit-declarations.js b/tests/lib/rules/no-unused-emit-declarations.js index 17b2f441b..cccbcbb98 100644 --- a/tests/lib/rules/no-unused-emit-declarations.js +++ b/tests/lib/rules/no-unused-emit-declarations.js @@ -369,6 +369,19 @@ tester.run('no-unused-emit-declarations', rule, { const m = defineModel('foo') ` + }, + { + filename: 'test.vue', + code: ` + + ` } ], invalid: [ @@ -750,6 +763,27 @@ tester.run('no-unused-emit-declarations', rule, { line: 3 } ] + }, + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + messageId: 'unused', + line: 4, + column: 19, + endColumn: 24 + } + ] } ] })