|
8 | 8 | mapToArray,
|
9 | 9 | arrayToMap,
|
10 | 10 | } from "./helpers.js";
|
| 11 | +import { isEmptyRecord } from "./utils/record.js"; |
11 | 12 |
|
12 | 13 | class LoggedSet extends Set<string> {
|
13 | 14 | private unvisited: Set<string>;
|
@@ -52,6 +53,24 @@ export function getExposedTypes(
|
52 | 53 | );
|
53 | 54 | }
|
54 | 55 |
|
| 56 | + if (webidl.mixins) { |
| 57 | + const allIncludes = Object.values(filtered.interfaces?.interface || {}) |
| 58 | + .map((i) => i.implements || []) |
| 59 | + .flat(); |
| 60 | + const mixins = deepFilter(webidl.mixins.mixin, (o) => exposesTo(o, target)); |
| 61 | + filtered.mixins!.mixin = filterProperties( |
| 62 | + mixins, |
| 63 | + (m: Browser.Interface) => allIncludes.includes(m.name) && !isEmptyMixin(m) |
| 64 | + ); |
| 65 | + for (const value of Object.values(filtered.interfaces!.interface || {})) { |
| 66 | + if (value.implements) { |
| 67 | + value.implements = value.implements.filter( |
| 68 | + (i) => !!filtered.mixins!.mixin[i] |
| 69 | + ); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
55 | 74 | const knownIDLTypes = new Set([
|
56 | 75 | ...followTypeReferences(webidl, filtered.interfaces!.interface),
|
57 | 76 | ...followTypeReferences(
|
@@ -92,10 +111,6 @@ export function getExposedTypes(
|
92 | 111 | );
|
93 | 112 | if (webidl.enums)
|
94 | 113 | filtered.enums!.enum = filterProperties(webidl.enums.enum, isKnownName);
|
95 |
| - if (webidl.mixins) { |
96 |
| - const mixins = deepFilter(webidl.mixins.mixin, (o) => exposesTo(o, target)); |
97 |
| - filtered.mixins!.mixin = filterProperties(mixins, isKnownName); |
98 |
| - } |
99 | 114 |
|
100 | 115 | for (const unvisited of forceKnownTypesLogged.unvisitedValues()) {
|
101 | 116 | console.warn(`${unvisited} is redundant in knownTypes.json (${target})`);
|
@@ -264,3 +279,14 @@ function flattenType(type: Browser.Typed[]) {
|
264 | 279 | }
|
265 | 280 | throw new Error("Cannot process empty union type");
|
266 | 281 | }
|
| 282 | + |
| 283 | +function isEmptyMixin(i?: Browser.Interface) { |
| 284 | + return ( |
| 285 | + !!i?.mixin && |
| 286 | + isEmptyRecord(i.properties?.property) && |
| 287 | + isEmptyRecord(i.methods?.method) && |
| 288 | + isEmptyRecord(i.constants?.constant) && |
| 289 | + !i.anonymousMethods?.method.length && |
| 290 | + !i.events?.event.length |
| 291 | + ); |
| 292 | +} |
0 commit comments