mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
fix(nuxt): don't match partial component names with prefix (#20939)
This commit is contained in:
parent
1aecd24361
commit
25c150136d
@ -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] &&
|
||||
|
@ -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', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user