fix(nuxt): don't match partial component names with prefix (#20939)

This commit is contained in:
Daniel Roe 2023-05-19 08:11:46 +01:00 committed by GitHub
parent 1aecd24361
commit 25c150136d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -130,13 +130,14 @@ export function resolveComponentName (fileName: string, prefixParts: string[]) {
* @example AwesomeComponent -> ['Awesome', 'Component']
*/
const fileNameParts = splitByCase(fileName)
const fileNamePartsContent = fileNameParts.join('').toLowerCase()
const fileNamePartsContent = fileNameParts.join('/').toLowerCase()
const componentNameParts: string[] = [...prefixParts]
let index = prefixParts.length - 1
const matchedSuffix:string[] = []
const matchedSuffix: string[] = []
while (index >= 0) {
matchedSuffix.unshift((prefixParts[index] || '').toLowerCase())
if (fileNamePartsContent.startsWith(matchedSuffix.join('')) ||
matchedSuffix.unshift(...splitByCase(prefixParts[index] || '').map(p => p.toLowerCase()))
const matchedSuffixContent = matchedSuffix.join('/')
if ((fileNamePartsContent === matchedSuffixContent || fileNamePartsContent.startsWith(matchedSuffixContent + '/')) ||
// e.g Item/Item/Item.vue -> Item
(prefixParts[index].toLowerCase() === fileNamePartsContent &&
prefixParts[index + 1] &&

View File

@ -257,7 +257,10 @@ const tests: Array<[string, string[], string]> = [
['ThingItemTest', ['Item', 'Thing', 'Foo'], 'ItemThingFooThingItemTest'],
['ItemIn', ['Item', 'Holder', 'Item', 'In'], 'ItemHolderItemIn'],
['Item', ['Item', 'Holder', 'Test'], 'ItemHolderTestItem'],
['ItemHolderItem', ['Item', 'Holder', 'Item', 'Holder'], 'ItemHolderItemHolderItem']
['ItemHolderItem', ['Item', 'Holder', 'Item', 'Holder'], 'ItemHolderItemHolderItem'],
['Icones', ['Icon'], 'IconIcones'],
['Icon', ['Icones'], 'IconesIcon'],
['IconHolder', ['IconHolder'], 'IconHolder']
]
describe('components:resolveComponentName', () => {