Skip to content

Commit f4c21e5

Browse files
authored
Fixed crash when the name property value was not literal, in no-unregistered-components rule (#1336)
1 parent 30da121 commit f4c21e5

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/rules/no-unregistered-components.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,12 @@ module.exports = {
185185
const nameProperty = utils.findProperty(obj, 'name')
186186

187187
if (nameProperty) {
188-
registeredComponents.push({
189-
node: nameProperty,
190-
name: nameProperty.value.value
191-
})
188+
if (nameProperty.value.type === 'Literal') {
189+
registeredComponents.push({
190+
node: nameProperty,
191+
name: `${nameProperty.value.value}`
192+
})
193+
}
192194
}
193195
})
194196
)

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,26 @@ tester.run('no-unregistered-components', rule, {
648648
line: 3
649649
}
650650
]
651+
},
652+
{
653+
filename: 'test.vue',
654+
code: `
655+
<template>
656+
<CustomComponent />
657+
</template>
658+
<script>
659+
export default {
660+
name: CustomComponent
661+
}
662+
</script>
663+
`,
664+
errors: [
665+
{
666+
message:
667+
'The "CustomComponent" component has been used but not registered.',
668+
line: 3
669+
}
670+
]
651671
}
652672
]
653673
})

0 commit comments

Comments
 (0)