Skip to content

Commit

Permalink
fix(no-unused-components): crash when :is in <component> is empty (
Browse files Browse the repository at this point in the history
…#793)

Fixed #789
  • Loading branch information
ota-meshi authored and michalsnik committed Feb 3, 2019
1 parent 98f7bbd commit 58d4a68
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/no-unused-components.js
Expand Up @@ -56,7 +56,11 @@ module.exports = {
usedComponents.add(node.rawName)
},
"VAttribute[directive=true][key.name='bind'][key.argument='is']" (node) {
if (node.value.type !== 'VExpressionContainer') return
if (
!node.value || // `<component :is>`
node.value.type !== 'VExpressionContainer' ||
!node.value.expression // `<component :is="">`
) return

if (node.value.expression.type === 'Literal') {
usedComponents.add(node.value.expression.value)
Expand Down
54 changes: 54 additions & 0 deletions tests/lib/rules/no-unused-components.js
Expand Up @@ -411,6 +411,22 @@ tester.run('no-unused-components', rule, {
}
}
</script>`
},

// empty `:is`
{
filename: 'test.vue',
code: `
<template>
<component :is=""></component>
</template>`
},
{
filename: 'test.vue',
code: `
<template>
<component :is></component>
</template>`
}
],
invalid: [
Expand Down Expand Up @@ -512,6 +528,44 @@ tester.run('no-unused-components', rule, {
message: 'The "Bar" component has been registered but not used.',
line: 14
}]
},

// empty `:is`
{
filename: 'test.vue',
code: `
<template>
<component :is=""></component>
</template>
<script>
export default {
components: {
Foo,
},
}
</script>`,
errors: [{
message: 'The "Foo" component has been registered but not used.',
line: 8
}]
},
{
filename: 'test.vue',
code: `
<template>
<component :is></component>
</template>
<script>
export default {
components: {
Foo,
},
}
</script>`,
errors: [{
message: 'The "Foo" component has been registered but not used.',
line: 8
}]
}
]
})

0 comments on commit 58d4a68

Please sign in to comment.