Skip to content

Commit 58d4a68

Browse files
ota-meshimichalsnik
authored andcommitted
fix(no-unused-components): crash when :is in <component> is empty (#793)
Fixed #789
1 parent 98f7bbd commit 58d4a68

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/rules/no-unused-components.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ module.exports = {
5656
usedComponents.add(node.rawName)
5757
},
5858
"VAttribute[directive=true][key.name='bind'][key.argument='is']" (node) {
59-
if (node.value.type !== 'VExpressionContainer') return
59+
if (
60+
!node.value || // `<component :is>`
61+
node.value.type !== 'VExpressionContainer' ||
62+
!node.value.expression // `<component :is="">`
63+
) return
6064

6165
if (node.value.expression.type === 'Literal') {
6266
usedComponents.add(node.value.expression.value)

tests/lib/rules/no-unused-components.js

+54
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,22 @@ tester.run('no-unused-components', rule, {
411411
}
412412
}
413413
</script>`
414+
},
415+
416+
// empty `:is`
417+
{
418+
filename: 'test.vue',
419+
code: `
420+
<template>
421+
<component :is=""></component>
422+
</template>`
423+
},
424+
{
425+
filename: 'test.vue',
426+
code: `
427+
<template>
428+
<component :is></component>
429+
</template>`
414430
}
415431
],
416432
invalid: [
@@ -512,6 +528,44 @@ tester.run('no-unused-components', rule, {
512528
message: 'The "Bar" component has been registered but not used.',
513529
line: 14
514530
}]
531+
},
532+
533+
// empty `:is`
534+
{
535+
filename: 'test.vue',
536+
code: `
537+
<template>
538+
<component :is=""></component>
539+
</template>
540+
<script>
541+
export default {
542+
components: {
543+
Foo,
544+
},
545+
}
546+
</script>`,
547+
errors: [{
548+
message: 'The "Foo" component has been registered but not used.',
549+
line: 8
550+
}]
551+
},
552+
{
553+
filename: 'test.vue',
554+
code: `
555+
<template>
556+
<component :is></component>
557+
</template>
558+
<script>
559+
export default {
560+
components: {
561+
Foo,
562+
},
563+
}
564+
</script>`,
565+
errors: [{
566+
message: 'The "Foo" component has been registered but not used.',
567+
line: 8
568+
}]
515569
}
516570
]
517571
})

0 commit comments

Comments
 (0)