Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue/no-unused-emit-declarations would throw Error when using dynamic render #2387

Closed
2 tasks done
ntnyq opened this issue Jan 31, 2024 · 0 comments · Fixed by #2388
Closed
2 tasks done

vue/no-unused-emit-declarations would throw Error when using dynamic render #2387

ntnyq opened this issue Jan 31, 2024 · 0 comments · Fixed by #2388
Labels

Comments

@ntnyq
Copy link
Contributor

ntnyq commented Jan 31, 2024

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 8.56.0
  • eslint-plugin-vue version: 9.21.0
  • Vue version: 3.4.15
  • Node version: 18.18.2
  • Operating System: MacOS

Please show your full configuration:

module.exports = {
  root: true,
  extends: ['plugin:vue/vue3-essential', 'eslint:recommended'],
  parserOptions: {
    ecmaVersion: 'latest',
  },
  rules: {
    'vue/no-unused-emit-declarations': 'error',
  },
}

What did you do?

<script>
import { defineComponent, h } from 'vue'

export default defineComponent({
  emits: ['update'],

  setup(_, ctx) {
    return () =>
      h(
        'button',
        {
          type: 'button',
          onClick: () => ctx.emit('update'),
        },
        'Click me!',
      )
  },
})
</script>

What did you expect to happen?

Lint works well.

What actually happened?

TypeError: Cannot read properties of undefined (reading 'name')
Occurred while linting /Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/src/VButton.vue:9
Rule: "vue/no-unused-emit-declarations"
    at isEmitVariableName (/Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint-plugin-vue@9.21.0_eslint@8.56.0/node_modules/eslint-plugin-vue/lib/rules/no-unused-emit-declarations.js:66:62)
    at Object.CallExpression (/Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint-plugin-vue@9.21.0_eslint@8.56.0/node_modules/eslint-plugin-vue/lib/rules/no-unused-emit-declarations.js:209:13)
    at callVisitor (/Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint-plugin-vue@9.21.0_eslint@8.56.0/node_modules/eslint-plugin-vue/lib/utils/index.js:1215:21)
    at vueVisitor.<computed> (/Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint-plugin-vue@9.21.0_eslint@8.56.0/node_modules/eslint-plugin-vue/lib/utils/index.js:1222:35)
    at ruleErrorHandler (/Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/Users/ntnyq/Desktop/github/ntnyq/repro-eslint-plugin-vue/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:326:22)

Repository to reproduce this issue

https://github.com/ntnyq-dev/repro-no-unused-emit-declarations

Additional text

#2340 introduced a function isEmitVariableName.

emitReferenceIds may be an empty Set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants