Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
farmaazon committed Jun 11, 2024
1 parent 77af509 commit 0d63f3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/gui2/src/util/__tests__/qualifiedName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ test.each([
test.each([
['local.Project.Main', 'Project', 'NewProject', 'local.NewProject.Main'],
['local.Project.Main', 'Project2', 'NewProject', 'local.Project.Main'],
['local.Project', 'Project', 'NewProject', 'local.NewPoject'],
['local.Project', 'Project', 'NewProject', 'local.NewProject'],
['Project', 'Project', 'NewProject', 'Project'],
['local.Project2.Project', 'Project', 'NewProject', 'local.Project2.Project'],
])('Replacing project name in $1 from $2 to $3', (qname, oldName, newName, expected) => {
])('Replacing project name in %s from %s to %s', (qname, oldName, newName, expected) => {
const qn = unwrap(tryQualifiedName(qname))
const newIdent = unwrap(tryIdentifier(newName))
expect(qnReplaceProjectName(qn, oldName, newIdent)).toBe(expected)
Expand Down
11 changes: 8 additions & 3 deletions app/gui2/src/util/qualifiedName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ export function qnIsTopElement(name: QualifiedName): boolean {
return !/[.].*?[.].*?[.]/.test(name)
}

/**
* Replace the project name in this qualified name if equal to `oldProject`, otherwise return `qn`.
*
* The namespace will be unchanged.
*/
export function qnReplaceProjectName(
qn: QualifiedName,
oldProject: string,
newProject: Identifier,
): QualifiedName {
return qn.replaceAll(
new RegExp(`^${identifierRegexPart}\\.${oldProject}`),
newProject,
return qn.replace(
new RegExp(`^(${identifierRegexPart}\\.)${oldProject}(?=\\.|$)`),
`$1${newProject}`,
) as QualifiedName
}

0 comments on commit 0d63f3c

Please sign in to comment.