Skip to content

Commit

Permalink
Fix multiple reflections mapping to the same file name
Browse files Browse the repository at this point in the history
I don't like this fix, but `getAlias` isn't something that should exist to begin with, so...

Resolves #2012
  • Loading branch information
Gerrit0 committed Jul 23, 2022
1 parent 55b72aa commit 3e5a1a2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- Fixed multiple reflections mapping to the same file name on case insensitive file systems, #2012.

## v0.23.8 (2022-07-17)

### Features
Expand Down
11 changes: 7 additions & 4 deletions src/lib/models/reflections/abstract.ts
Expand Up @@ -413,6 +413,9 @@ export abstract class Reflection {
if (alias === "") {
alias = "reflection-" + this.id;
}
// NTFS/ExFAT use uppercase, so we will too. It probably won't matter
// in this case since names will generally be valid identifiers, but to be safe...
const upperAlias = alias.toUpperCase();

let target = this as Reflection;
while (target.parent && !target.hasOwnDocument) {
Expand All @@ -422,12 +425,12 @@ export abstract class Reflection {
target._aliases ||= new Map();

let suffix = "";
if (!target._aliases.has(alias)) {
target._aliases.set(alias, 1);
if (!target._aliases.has(upperAlias)) {
target._aliases.set(upperAlias, 1);
} else {
const count = target._aliases.get(alias)!;
const count = target._aliases.get(upperAlias)!;
suffix = "-" + count.toString();
target._aliases.set(alias, count + 1);
target._aliases.set(upperAlias, count + 1);
}

alias += suffix;
Expand Down
6 changes: 6 additions & 0 deletions src/test/converter2/issues/gh2012.ts
@@ -0,0 +1,6 @@
export function model(): number {
return 1;
}
export function Model(): string {
return "";
}
8 changes: 8 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -665,4 +665,12 @@ export const issueTests: {
equal(b.signatures![0].sources?.[0].line, 3);
equal(b.signatures![0].sources?.[0].character, 0);
},

gh2012(project) {
project.hasOwnDocument = true;
const model = query(project, "model");
const Model = query(project, "Model");
equal(model.getAlias(), "model");
equal(Model.getAlias(), "Model-1");
},
};

0 comments on commit 3e5a1a2

Please sign in to comment.