Skip to content

Commit 32da294

Browse files
committed
fix: use Map instead of an array for ObjectBuilder
Map iteration is done in insertion order so there are no functional drawbacks. This change makes sure that there can only be a single property with the same name. It was a known flaw but a non-issue with our limited usage. Fixing the issues makes CR happier.
1 parent eec5c81 commit 32da294

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: packages/cli/src/sourcegen/objectbuilder.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function object (build: (builder: ObjectValueBuilder) => void, options?:
1616
}
1717

1818
export class ObjectValueBuilder {
19-
#properties: ObjectProperty[] = []
19+
#properties = new Map<string, ObjectProperty>()
2020
#options?: ObjectValueOptions
2121

2222
constructor (options?: ObjectValueOptions) {
@@ -65,11 +65,11 @@ export class ObjectValueBuilder {
6565
}
6666

6767
value (name: string, value: Value, options?: ObjectPropertyOptions): this {
68-
this.#properties.push(new ObjectProperty(name, value, options))
68+
this.#properties.set(name, new ObjectProperty(name, value, options))
6969
return this
7070
}
7171

7272
build (): ObjectValue {
73-
return new ObjectValue(this.#properties, this.#options)
73+
return new ObjectValue([...this.#properties.values()], this.#options)
7474
}
7575
}

0 commit comments

Comments
 (0)