Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
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
}
}
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ tester.run('no-undef-components', rule, {
}
]
},
{
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
Original file line number Diff line number Diff line change
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