Do not add duplicate entries to description dictionary

This commit is contained in:
Christopher Schleiden
2023-01-11 13:28:53 -08:00
parent 031e1b474b
commit b322bcb32b
2 changed files with 7 additions and 1 deletions
@@ -12,7 +12,8 @@ describe("description dictionary", () => {
it("does not add duplicate entries", () => {
const d = new DescriptionDictionary();
d.add("ABC", new StringData("val1"));
d.add("abc", new StringData("val2"));
d.add("ABC", new StringData("val2"));
d.add("abc", new StringData("val3"));
expect(d.pairs()).toEqual([{key: "ABC", value: new StringData("val1")}]);
});
@@ -19,6 +19,11 @@ export class DescriptionDictionary extends Dictionary {
}
override add(key: string, value: ExpressionData, description?: string): void {
if (this.get(key) !== undefined) {
// Key already added, ignore
return;
}
super.add(key, value);
if (description) {
this.descriptions.set(key, description);