Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/linter/ui5Types/utils/UniqueNameCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,23 @@ export const getUniqueName = function (
let candidate = adjustCase(sResultName);
if (!isValidIdentifierName(candidate)) {
candidate = adjustCase("O") + sResultName;
if (!isValidIdentifierName(candidate)) {
throw new Error(`Failed to create a valid identifier name for '${sResultName}', tried '${candidate}'`);
}
}
sResultName = candidate;

// add suffix to make it unique
candidate = sResultName;
const iMaxIterations = 100;
for (let i = 0; i < iMaxIterations; i++) {
if (
isValidIdentifierName(candidate) &&
!alreadyExists(usedNames, candidate, additionalCheck)
) {
return candidate;
}
let i = 0;
while (alreadyExists(usedNames, candidate, additionalCheck)) {
candidate = sResultName + i;
if (!isValidIdentifierName(candidate)) {
throw new Error(`Invalid unique identifier name '${candidate}' for '${sResultName}'`);
}
i++;
}

throw new Error(
`Did not find a valid unique name for ${sResultName} within ${
iMaxIterations - 1
} iterations.`
);
return candidate;
};

/**
Expand Down
115 changes: 115 additions & 0 deletions test/fixtures/transpiler/xml/LargeXMLViewUniqueIdentifiers.view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<mvc:View xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
xmlns:table="sap.ui.table"
xmlns:tablePlugins="sap.ui.table.plugins"
controllerName="com.myapp.controller.Main"
>

<!-- Having the same control over 100 times should not cause issues when creating unique identifiers -->
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />
<Text text="Foo" />

</mvc:View>
Loading