Skip to content

Commit 829b12e

Browse files
committed
Merge branch 'gh-2843' of https://github.com/IlyaSemenov/svelte into IlyaSemenov-gh-2843
2 parents 32107d8 + 181f60d commit 829b12e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/compiler/compile/index.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,25 @@ function get_name(filename: string) {
6060
// eslint-disable-next-line no-useless-escape
6161
const parts = filename.split(/[\/\\]/);
6262

63-
if (parts.length > 1 && /^index\.\w+/.test(parts[parts.length - 1])) {
64-
parts.pop();
63+
if (parts.length > 1) {
64+
const index_match = parts[parts.length - 1].match(/^index(\.\w+)/);
65+
if (index_match) {
66+
parts.pop();
67+
parts[parts.length - 1] += index_match[1];
68+
}
6569
}
6670

6771
const base = parts.pop()
68-
.replace(/\..+/, "")
72+
.replace(/\.[^.]+$/, "")
6973
.replace(/[^a-zA-Z_$0-9]+/g, '_')
7074
.replace(/^_/, '')
7175
.replace(/_$/, '')
7276
.replace(/^(\d)/, '_$1');
7377

78+
if (!base) {
79+
throw new Error(`Could not derive component name from file ${filename}`);
80+
}
81+
7482
return base[0].toUpperCase() + base.slice(1);
7583
}
7684

0 commit comments

Comments
 (0)