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

Fix detect Nuxt3 defineNuxtComponent #2311

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/utils/index.js
Expand Up @@ -1361,7 +1361,7 @@ module.exports = {
* Get the Vue component definition type from given node
* Vue.component('xxx', {}) || component('xxx', {})
* @param {ObjectExpression} node Node to check
* @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | null}
* @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | 'defineNuxtComponent' | null}
*/
getVueComponentDefinitionType,
/**
Expand Down Expand Up @@ -2502,7 +2502,7 @@ function isVueComponentFile(node, path) {
* Get the Vue component definition type from given node
* Vue.component('xxx', {}) || component('xxx', {})
* @param {ObjectExpression} node Node to check
* @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | null}
* @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | 'defineNuxtComponent' | null}
*/
function getVueComponentDefinitionType(node) {
const parent = getParent(node)
Expand Down Expand Up @@ -2558,6 +2558,12 @@ function getVueComponentDefinitionType(node) {
const isDestructedVueComponent = isObjectArgument(parent)
return isDestructedVueComponent ? 'defineComponent' : null
}
if (callee.name === 'defineNuxtComponent') {
// for Nuxt 3.x
// defineNuxtComponent({})
const isDestructedVueComponent = isObjectArgument(parent)
return isDestructedVueComponent ? 'defineComponent' : null
FloEdelmann marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down Expand Up @@ -2702,7 +2708,9 @@ function isSFCObject(context, node) {
}
const { callee } = parent
if (
(callee.type === 'Identifier' && callee.name === 'defineComponent') ||
(callee.type === 'Identifier' &&
(callee.name === 'defineComponent' ||
callee.name === 'defineNuxtComponent')) ||
(callee.type === 'MemberExpression' &&
callee.object.type === 'Identifier' &&
callee.object.name === 'Vue' &&
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/rules/no-undef-components.js
Expand Up @@ -265,6 +265,21 @@ tester.run('no-undef-components', rule, {
}
]
},
{
FloEdelmann marked this conversation as resolved.
Show resolved Hide resolved
filename: 'test.vue',
code: `
<template>
<CustomComponent />
</template>
<script>
export default defineNuxtComponent({
components: {
CustomComponent
}
})
</script>
`
},
{
filename: 'test.vue',
code: `
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/utils/vue-component.js
Expand Up @@ -313,6 +313,12 @@ function invalidTests(ext) {
code: `export default defineComponent({})`,
parserOptions,
errors: [makeError(1)]
},
{
filename: `test.${ext}`,
code: `export default defineNuxtComponent({})`,
parserOptions,
errors: [makeError(1)]
}
]
}
Expand Down