diff --git a/lib/utils/index.js b/lib/utils/index.js
index e2af0257f..4c90e310b 100644
--- a/lib/utils/index.js
+++ b/lib/utils/index.js
@@ -265,10 +265,11 @@ module.exports = {
return componentsNode.value.properties
.filter(p => p.type === 'Property')
- .map(node => ({
- node,
- name: this.getStaticPropertyName(node.key)
- }))
+ .map(node => {
+ const name = this.getStaticPropertyName(node)
+ return name ? { node, name } : null
+ })
+ .filter(comp => comp != null)
},
/**
diff --git a/tests/lib/rules/no-unused-components.js b/tests/lib/rules/no-unused-components.js
index b8dfcaaf2..a03625972 100644
--- a/tests/lib/rules/no-unused-components.js
+++ b/tests/lib/rules/no-unused-components.js
@@ -427,6 +427,50 @@ tester.run('no-unused-components', rule, {
`
+ },
+
+ // computed properties
+ {
+ filename: 'test.vue',
+ code: `
+
+
+
+ `
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+
+
+ `
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+
+
+ `
}
],
invalid: [
@@ -566,6 +610,40 @@ tester.run('no-unused-components', rule, {
message: 'The "Foo" component has been registered but not used.',
line: 8
}]
+ },
+
+ // computed properties
+ {
+ filename: 'test.vue',
+ code: `
+
+
+
+ `,
+ errors: [{
+ message: 'The "foo" component has been registered but not used.',
+ line: 8
+ }, {
+ message: 'The "bar" component has been registered but not used.',
+ line: 9
+ }, {
+ message: 'The "baz" component has been registered but not used.',
+ line: 10
+ }, {
+ message: 'The "quux" component has been registered but not used.',
+ line: 13
+ }]
}
]
})
diff --git a/tests/lib/utils/index.js b/tests/lib/utils/index.js
index 0b8c07e2d..f698a98ef 100644
--- a/tests/lib/utils/index.js
+++ b/tests/lib/utils/index.js
@@ -246,6 +246,25 @@ describe('getRegisteredComponents', () => {
['PrimaryButton', 'secondaryButton', 'the-modal', 'the_dropdown', 'the_input', 'SomeComponent'],
)
})
+
+ it('should return an array of only components whose names can be identified', () => {
+ node = parse(`const test = {
+ name: 'test',
+ components: {
+ ...test,
+ Foo,
+ [bar]: Bar,
+ [baz.baz]: Baz,
+ [\`\${qux}\`]: Qux,
+ [\`Quux\`]: Quux
+ }
+ }`)
+
+ assert.deepEqual(
+ utils.getRegisteredComponents(node).map(c => c.name),
+ ['Foo', 'Quux'],
+ )
+ })
})
describe('getComponentProps', () => {