Skip to content

Commit b93e739

Browse files
committed
Refactor emitFlavor function to streamline file generation for Web IDL signatures
1 parent 8517969 commit b93e739

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

src/build.ts

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,35 @@ async function emitFlavor(
5151
mergeNamesakes(exposed);
5252
exposed.events = webidl.events;
5353

54-
const result = emitWebIdl(
55-
exposed,
56-
options.global[0],
57-
"",
58-
options.compilerBehavior,
59-
);
60-
await fs.writeFile(
61-
new URL(`${options.name}.generated.d.ts`, options.outputFolder),
62-
result,
63-
);
64-
65-
const iterators = emitWebIdl(
66-
exposed,
67-
options.global[0],
68-
"sync",
69-
options.compilerBehavior,
70-
);
71-
await fs.writeFile(
72-
new URL(`${options.name}.iterable.generated.d.ts`, options.outputFolder),
73-
iterators,
74-
);
54+
// Helper to emit and write multiple signatures
55+
const outputs = [
56+
{
57+
suffix: ".generated.d.ts",
58+
signature: "",
59+
},
60+
{
61+
suffix: ".iterable.generated.d.ts",
62+
signature: "sync",
63+
},
64+
{
65+
suffix: ".asynciterable.generated.d.ts",
66+
signature: "async",
67+
},
68+
] as const;
7569

76-
const asyncIterators = emitWebIdl(
77-
exposed,
78-
options.global[0],
79-
"async",
80-
options.compilerBehavior,
81-
);
82-
await fs.writeFile(
83-
new URL(
84-
`${options.name}.asynciterable.generated.d.ts`,
85-
options.outputFolder,
86-
),
87-
asyncIterators,
70+
await Promise.all(
71+
outputs.map(async ({ suffix, signature }) => {
72+
const content = emitWebIdl(
73+
exposed,
74+
options.global[0],
75+
signature,
76+
options.compilerBehavior,
77+
);
78+
await fs.writeFile(
79+
new URL(`${options.name}${suffix}`, options.outputFolder),
80+
content,
81+
);
82+
})
8883
);
8984
}
9085

0 commit comments

Comments
 (0)