From 181f60d4f80a8b894a150caad0efd4162d10ed0a Mon Sep 17 00:00:00 2001 From: Ilya Semenov Date: Mon, 10 Jun 2019 17:53:10 +0700 Subject: [PATCH] Improve file name to component name conversion, fix #2843 --- src/compiler/compile/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/compile/index.ts b/src/compiler/compile/index.ts index 3f4a3eeb32..896f235c61 100644 --- a/src/compiler/compile/index.ts +++ b/src/compiler/compile/index.ts @@ -60,17 +60,25 @@ function get_name(filename: string) { // eslint-disable-next-line no-useless-escape const parts = filename.split(/[\/\\]/); - if (parts.length > 1 && /^index\.\w+/.test(parts[parts.length - 1])) { - parts.pop(); + if (parts.length > 1) { + const index_match = parts[parts.length - 1].match(/^index(\.\w+)/); + if (index_match) { + parts.pop(); + parts[parts.length - 1] += index_match[1]; + } } const base = parts.pop() - .replace(/\..+/, "") + .replace(/\.[^.]+$/, "") .replace(/[^a-zA-Z_$0-9]+/g, '_') .replace(/^_/, '') .replace(/_$/, '') .replace(/^(\d)/, '_$1'); + if (!base) { + throw new Error(`Could not derive component name from file ${filename}`); + } + return base[0].toUpperCase() + base.slice(1); }