Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…IlyaSemenov-gh-2843
  • Loading branch information
Rich-Harris committed Jun 16, 2019
2 parents 32107d8 + 181f60d commit 829b12e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/compiler/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 829b12e

Please sign in to comment.