|
1 | 1 | import * as Browser from "./build/types.js";
|
2 | 2 | import { promises as fs } from "fs";
|
3 |
| -import { merge, resolveExposure, arrayToMap } from "./build/helpers.js"; |
| 3 | +import { merge, resolveExposure, arrayToMap, clone } from "./build/helpers.js"; |
4 | 4 | import { type CompilerBehavior, emitWebIdl } from "./build/emitter.js";
|
5 | 5 | import { convert } from "./build/widlprocess.js";
|
6 | 6 | import { getExposedTypes } from "./build/expose.js";
|
@@ -291,52 +291,83 @@ async function emitDom() {
|
291 | 291 |
|
292 | 292 | const knownTypes = await readInputJSON("knownTypes.json");
|
293 | 293 |
|
294 |
| - const emitVariations = [ |
| 294 | + interface Variation { |
| 295 | + outputFolder: URL; |
| 296 | + compilerBehavior: CompilerBehavior; |
| 297 | + overriddenItems?: Browser.WebIdl; |
| 298 | + } |
| 299 | + |
| 300 | + const emitVariations: Variation[] = [ |
| 301 | + // ts5.7 (and later) |
| 302 | + // - introduced generic typed arrays over `ArrayBufferLike` |
295 | 303 | {
|
296 |
| - outputFolder: new URL("./ts5.5/", outputFolder), |
297 |
| - compilerBehavior: {}, |
| 304 | + outputFolder, |
| 305 | + compilerBehavior: { |
| 306 | + useIteratorObject: true, |
| 307 | + allowUnrelatedSetterType: true, |
| 308 | + }, |
298 | 309 | },
|
| 310 | + // ts5.6 |
| 311 | + // - introduced support for `IteratorObject`/Iterator helpers and unrelated setter types |
299 | 312 | {
|
300 |
| - outputFolder, |
| 313 | + outputFolder: new URL("./ts5.6/", outputFolder), |
| 314 | + overriddenItems: await readInputJSON("overridingTypes.ts5.6.jsonc"), // ts5.6 does not support generic typed arrays |
301 | 315 | compilerBehavior: {
|
302 | 316 | useIteratorObject: true,
|
303 | 317 | allowUnrelatedSetterType: true,
|
304 |
| - } as CompilerBehavior, |
| 318 | + }, |
| 319 | + }, |
| 320 | + // ts5.5 (and earlier) |
| 321 | + { |
| 322 | + outputFolder: new URL("./ts5.5/", outputFolder), |
| 323 | + overriddenItems: await readInputJSON("overridingTypes.ts5.6.jsonc"), // ts5.5 does not support generic typed arrays |
| 324 | + compilerBehavior: {}, // ts5.5 does not support `IteratorObject` or unrelated setter types |
305 | 325 | },
|
306 | 326 | ];
|
307 | 327 |
|
308 |
| - for (const { outputFolder, compilerBehavior } of emitVariations) { |
| 328 | + for (const { |
| 329 | + outputFolder, |
| 330 | + compilerBehavior, |
| 331 | + overriddenItems, |
| 332 | + } of emitVariations) { |
309 | 333 | // Create output folder
|
310 | 334 | await fs.mkdir(outputFolder, {
|
311 | 335 | // Doesn't need to be recursive, but this helpfully ignores EEXIST
|
312 | 336 | recursive: true,
|
313 | 337 | });
|
314 | 338 |
|
315 |
| - emitFlavor(webidl, new Set(knownTypes.Window), { |
| 339 | + // apply changes specific to the variation |
| 340 | + let variationWebidl = webidl; |
| 341 | + if (overriddenItems) { |
| 342 | + variationWebidl = clone(webidl); |
| 343 | + variationWebidl = merge(variationWebidl, overriddenItems); |
| 344 | + } |
| 345 | + |
| 346 | + emitFlavor(variationWebidl, new Set(knownTypes.Window), { |
316 | 347 | name: "dom",
|
317 | 348 | global: ["Window"],
|
318 | 349 | outputFolder,
|
319 | 350 | compilerBehavior,
|
320 | 351 | });
|
321 |
| - emitFlavor(webidl, new Set(knownTypes.Worker), { |
| 352 | + emitFlavor(variationWebidl, new Set(knownTypes.Worker), { |
322 | 353 | name: "webworker",
|
323 | 354 | global: ["Worker", "DedicatedWorker", "SharedWorker", "ServiceWorker"],
|
324 | 355 | outputFolder,
|
325 | 356 | compilerBehavior,
|
326 | 357 | });
|
327 |
| - emitFlavor(webidl, new Set(knownTypes.Worker), { |
| 358 | + emitFlavor(variationWebidl, new Set(knownTypes.Worker), { |
328 | 359 | name: "sharedworker",
|
329 | 360 | global: ["SharedWorker", "Worker"],
|
330 | 361 | outputFolder,
|
331 | 362 | compilerBehavior,
|
332 | 363 | });
|
333 |
| - emitFlavor(webidl, new Set(knownTypes.Worker), { |
| 364 | + emitFlavor(variationWebidl, new Set(knownTypes.Worker), { |
334 | 365 | name: "serviceworker",
|
335 | 366 | global: ["ServiceWorker", "Worker"],
|
336 | 367 | outputFolder,
|
337 | 368 | compilerBehavior,
|
338 | 369 | });
|
339 |
| - emitFlavor(webidl, new Set(knownTypes.Worklet), { |
| 370 | + emitFlavor(variationWebidl, new Set(knownTypes.Worklet), { |
340 | 371 | name: "audioworklet",
|
341 | 372 | global: ["AudioWorklet", "Worklet"],
|
342 | 373 | outputFolder,
|
|
0 commit comments