Skip to content

Commit b9ccd7c

Browse files
committed
fix: don't generate duplicate imports
1 parent baa1c03 commit b9ccd7c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import { IdentifierValue } from './identifier'
66
type Content = Declaration | Value
77

88
export class Program {
9-
#imports = new Map<string, string[]>()
9+
#imports = new Map<string, Set<string>>()
1010
#variables = new Map<string, IdentifierValue>()
1111
#counters = new Map<string, number>()
1212
#sections: Content[] = []
1313

1414
import (type: string, from: string) {
15-
this.#imports.set(from, (this.#imports.get(from) || []).concat([type]))
15+
if (this.#imports.has(from)) {
16+
this.#imports.get(from)?.add(type)
17+
} else {
18+
this.#imports.set(from, new Set([type]))
19+
}
1620
}
1721

1822
#inc (key: string): number {
@@ -46,7 +50,7 @@ export class Program {
4650
output.cosmeticWhitespace()
4751
output.append('{')
4852
let first = true
49-
for (const type of types) {
53+
for (const type of Array.from(types).sort()) {
5054
if (!first) {
5155
output.append(',')
5256
}

0 commit comments

Comments
 (0)