Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5cb5fef

Browse files
sugitataota-meshi
authored andcommitted
Fix detect Nuxt3 defineNuxtComponent (#2311)
1 parent ddfd676 commit 5cb5fef

File tree

4 files changed

+110
-3
lines changed

4 files changed

+110
-3
lines changed

‎lib/utils/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ module.exports = {
15811581
* Get the Vue component definition type from given node
15821582
* Vue.component('xxx', {}) || component('xxx', {})
15831583
* @param {ObjectExpression} node Node to check
1584-
* @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | null}
1584+
* @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | 'defineNuxtComponent' | null}
15851585
*/
15861586
getVueComponentDefinitionType,
15871587
/**
@@ -2755,7 +2755,7 @@ function isVueComponentFile(node, path) {
27552755
* Get the Vue component definition type from given node
27562756
* Vue.component('xxx', {}) || component('xxx', {})
27572757
* @param {ObjectExpression} node Node to check
2758-
* @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | null}
2758+
* @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | 'defineNuxtComponent' | null}
27592759
*/
27602760
function getVueComponentDefinitionType(node) {
27612761
const parent = getParent(node)
@@ -2811,6 +2811,12 @@ function getVueComponentDefinitionType(node) {
28112811
const isDestructedVueComponent = isObjectArgument(parent)
28122812
return isDestructedVueComponent ? 'defineComponent' : null
28132813
}
2814+
if (callee.name === 'defineNuxtComponent') {
2815+
// for Nuxt 3.x
2816+
// defineNuxtComponent({})
2817+
const isDestructedVueComponent = isObjectArgument(parent)
2818+
return isDestructedVueComponent ? 'defineNuxtComponent' : null
2819+
}
28142820
}
28152821
}
28162822

@@ -2955,7 +2961,9 @@ function isSFCObject(context, node) {
29552961
}
29562962
const { callee } = parent
29572963
if (
2958-
(callee.type === 'Identifier' && callee.name === 'defineComponent') ||
2964+
(callee.type === 'Identifier' &&
2965+
(callee.name === 'defineComponent' ||
2966+
callee.name === 'defineNuxtComponent')) ||
29592967
(callee.type === 'MemberExpression' &&
29602968
callee.object.type === 'Identifier' &&
29612969
callee.object.name === 'Vue' &&

‎tests/lib/rules/no-undef-components.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,21 @@ tester.run('no-undef-components', rule, {
269269
}
270270
]
271271
},
272+
{
273+
filename: 'test.vue',
274+
code: `
275+
<template>
276+
<CustomComponent />
277+
</template>
278+
<script>
279+
export default defineNuxtComponent({
280+
components: {
281+
CustomComponent
282+
}
283+
})
284+
</script>
285+
`
286+
},
272287
{
273288
filename: 'test.vue',
274289
code: `

‎tests/lib/rules/order-in-components.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,84 @@ ruleTester.run('order-in-components', rule, {
234234
}
235235
]
236236
},
237+
{
238+
filename: 'test.vue',
239+
code: `
240+
import { defineComponent } from 'vue'
241+
export default defineComponent({
242+
name: 'app',
243+
data () {
244+
return {
245+
msg: 'Welcome to Your Vue.js App'
246+
}
247+
},
248+
props: {
249+
propA: Number,
250+
},
251+
})
252+
`,
253+
output: `
254+
import { defineComponent } from 'vue'
255+
export default defineComponent({
256+
name: 'app',
257+
props: {
258+
propA: Number,
259+
},
260+
data () {
261+
return {
262+
msg: 'Welcome to Your Vue.js App'
263+
}
264+
},
265+
})
266+
`,
267+
languageOptions,
268+
errors: [
269+
{
270+
message:
271+
'The "props" property should be above the "data" property on line 5.',
272+
line: 10
273+
}
274+
]
275+
},
276+
{
277+
filename: 'test.vue',
278+
code: `
279+
import { defineNuxtComponent } from '#app'
280+
export default defineNuxtComponent({
281+
name: 'app',
282+
data () {
283+
return {
284+
msg: 'Welcome to Your Vue.js App'
285+
}
286+
},
287+
props: {
288+
propA: Number,
289+
},
290+
})
291+
`,
292+
output: `
293+
import { defineNuxtComponent } from '#app'
294+
export default defineNuxtComponent({
295+
name: 'app',
296+
props: {
297+
propA: Number,
298+
},
299+
data () {
300+
return {
301+
msg: 'Welcome to Your Vue.js App'
302+
}
303+
},
304+
})
305+
`,
306+
languageOptions,
307+
errors: [
308+
{
309+
message:
310+
'The "props" property should be above the "data" property on line 5.',
311+
line: 10
312+
}
313+
]
314+
},
237315
{
238316
filename: 'test.jsx',
239317
code: `

‎tests/lib/utils/vue-component.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ function invalidTests(ext) {
325325
code: `export default defineComponent({})`,
326326
languageOptions,
327327
errors: [makeError(1)]
328+
},
329+
{
330+
filename: `test.${ext}`,
331+
code: `export default defineNuxtComponent({})`,
332+
languageOptions,
333+
errors: [makeError(1)]
328334
}
329335
]
330336
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /