Skip to content

Commit 027128c

Browse files
authored
fix(utils): collapse prefixes in PascalCase name (unplugin#744)
1 parent aeaf51d commit 027128c

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
export default {
3+
name: 'KebabCaseFile',
4+
}
5+
</script>
6+
7+
<template>
8+
<h3>KebabCaseFile Component: <code>kebab-case/KebabCaseFile.vue</code></h3>
9+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
export default {
3+
name: 'KebabCaseCollapseFile',
4+
}
5+
</script>
6+
7+
<template>
8+
<h3>KebabCaseCollapseFile Component: <code>kebab-case/kebab-case-collapse/KebabCaseCollapseFile.vue</code></h3>
9+
</template>

src/core/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,13 @@ export function getNameFromFilePath(filePath: string, options: ResolvedOptions):
159159
for (const fileOrFolderName of namespaced) {
160160
let cumulativePrefix = ''
161161
let didCollapse = false
162+
const pascalCasedName = pascalCase(fileOrFolderName)
162163

163164
for (const parentFolder of [...collapsed].reverse()) {
164-
cumulativePrefix = `${capitalize(parentFolder)}${cumulativePrefix}`
165+
cumulativePrefix = `${parentFolder}${cumulativePrefix}`
165166

166-
if (pascalCase(fileOrFolderName).startsWith(pascalCase(cumulativePrefix))) {
167-
const collapseSamePrefix = fileOrFolderName.slice(cumulativePrefix.length)
167+
if (pascalCasedName.startsWith(cumulativePrefix)) {
168+
const collapseSamePrefix = pascalCasedName.slice(cumulativePrefix.length)
168169

169170
collapsed.push(collapseSamePrefix)
170171

@@ -174,7 +175,7 @@ export function getNameFromFilePath(filePath: string, options: ResolvedOptions):
174175
}
175176

176177
if (!didCollapse)
177-
collapsed.push(fileOrFolderName)
178+
collapsed.push(pascalCasedName)
178179
}
179180

180181
namespaced = collapsed

test/__snapshots__/search.test.ts.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ exports[`search > should with namespace & collapse 1`] = `
3838
"as": "ComponentD",
3939
"from": "src/components/ComponentD.vue",
4040
},
41+
{
42+
"as": "KebabCaseCollapseFile",
43+
"from": "src/components/kebab-case/kebab-case-collapse/KebabCaseCollapseFile.vue",
44+
},
45+
{
46+
"as": "KebabCaseFile",
47+
"from": "src/components/kebab-case/KebabCaseFile.vue",
48+
},
4149
{
4250
"as": "Recursive",
4351
"from": "src/components/Recursive.vue",
@@ -91,6 +99,14 @@ exports[`search > should with namespace 1`] = `
9199
"as": "ComponentD",
92100
"from": "src/components/ComponentD.vue",
93101
},
102+
{
103+
"as": "KebabCaseKebabCaseCollapseKebabCaseCollapseFile",
104+
"from": "src/components/kebab-case/kebab-case-collapse/KebabCaseCollapseFile.vue",
105+
},
106+
{
107+
"as": "KebabCaseKebabCaseFile",
108+
"from": "src/components/kebab-case/KebabCaseFile.vue",
109+
},
94110
{
95111
"as": "Recursive",
96112
"from": "src/components/Recursive.vue",
@@ -152,6 +168,14 @@ exports[`search > should work 1`] = `
152168
"as": "FolderAndComponentPartially",
153169
"from": "src/components/collapse/collapseFolder/FolderAndComponentPartially.vue",
154170
},
171+
{
172+
"as": "KebabCaseCollapseFile",
173+
"from": "src/components/kebab-case/kebab-case-collapse/KebabCaseCollapseFile.vue",
174+
},
175+
{
176+
"as": "KebabCaseFile",
177+
"from": "src/components/kebab-case/KebabCaseFile.vue",
178+
},
155179
{
156180
"as": "Recursive",
157181
"from": "src/components/Recursive.vue",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy