diff --git a/inputfiles/removedTypes.jsonc b/inputfiles/removedTypes.jsonc index 78641cd12..6bf7c1297 100644 --- a/inputfiles/removedTypes.jsonc +++ b/inputfiles/removedTypes.jsonc @@ -51,25 +51,7 @@ "elementFromPoint": null, "elementsFromPoint": null } - }, - "implements": ["GeometryUtils"] - }, - "Element": { - "implements": ["GeometryUtils", "Region"] - }, - "Navigator": { - "implements": [ - "NavigatorBadge", - "NavigatorDeviceMemory", - "NavigatorFonts", - "NavigatorGPU", - "NavigatorML", - "NavigatorNetworkInformation", - "NavigatorUA" - ] - }, - "NetworkInformation": { - "implements": ["NetworkInformationSaveData"] + } }, "Response": { "methods": { @@ -91,9 +73,6 @@ } } }, - "SVGElement": { - "implements": ["SVGElementInstance"] - }, "SVGFEGaussianBlurElement": { "constants": { "constant": { @@ -104,9 +83,6 @@ } } }, - "Text": { - "implements": ["GeometryUtils"] - }, "WebGLBuffer": { "extends": null }, @@ -142,17 +118,6 @@ }, "WebGLVertexArrayObjectOES": { "extends": null - }, - "WorkerNavigator": { - "implements": [ - "NavigatorBadge", - "NavigatorDeviceMemory", - "NavigatorFonts", - "NavigatorGPU", - "NavigatorML", - "NavigatorNetworkInformation", - "NavigatorUA" - ] } } }, @@ -576,6 +541,18 @@ } } }, + "mixins": { + "mixin":{ + "NavigatorNetworkInformation": { + "properties": { + "property": { + // https://github.com/mdn/browser-compat-data/pull/17824 + "connection": null + } + } + } + } + }, "typedefs": { "typedef": [ "ArrayBufferView" diff --git a/src/build/bcd.ts b/src/build/bcd.ts index 2297aa1be..8df4385e8 100644 --- a/src/build/bcd.ts +++ b/src/build/bcd.ts @@ -52,8 +52,9 @@ function isSuitable( export function getRemovalData(webidl: Browser.WebIdl): Browser.WebIdl { return mapToBcdCompat(webidl, ({ key, parentKey, compat, mixin }) => { - // Allow all mixins for now, but not their members - // Ultimately expose.ts should be updated to check empty mixins + // Allow all mixins here, but not their members. + // Empty mixins created by this will be managed by exposed.ts. + // (It's better to manage mixins there as mixins can also conditionally be empty by exposure settings) if (mixin && !parentKey) { return; } diff --git a/src/build/expose.ts b/src/build/expose.ts index 4a0da7d1a..8fcbeb4e2 100644 --- a/src/build/expose.ts +++ b/src/build/expose.ts @@ -8,6 +8,7 @@ import { mapToArray, arrayToMap, } from "./helpers.js"; +import { isEmptyRecord } from "./utils/record.js"; class LoggedSet extends Set { private unvisited: Set; @@ -52,6 +53,24 @@ export function getExposedTypes( ); } + if (webidl.mixins) { + const allIncludes = Object.values(filtered.interfaces?.interface || {}) + .map((i) => i.implements || []) + .flat(); + const mixins = deepFilter(webidl.mixins.mixin, (o) => exposesTo(o, target)); + filtered.mixins!.mixin = filterProperties( + mixins, + (m: Browser.Interface) => allIncludes.includes(m.name) && !isEmptyMixin(m) + ); + for (const value of Object.values(filtered.interfaces!.interface || {})) { + if (value.implements) { + value.implements = value.implements.filter( + (i) => !!filtered.mixins!.mixin[i] + ); + } + } + } + const knownIDLTypes = new Set([ ...followTypeReferences(webidl, filtered.interfaces!.interface), ...followTypeReferences( @@ -92,10 +111,6 @@ export function getExposedTypes( ); if (webidl.enums) filtered.enums!.enum = filterProperties(webidl.enums.enum, isKnownName); - if (webidl.mixins) { - const mixins = deepFilter(webidl.mixins.mixin, (o) => exposesTo(o, target)); - filtered.mixins!.mixin = filterProperties(mixins, isKnownName); - } for (const unvisited of forceKnownTypesLogged.unvisitedValues()) { console.warn(`${unvisited} is redundant in knownTypes.json (${target})`); @@ -264,3 +279,14 @@ function flattenType(type: Browser.Typed[]) { } throw new Error("Cannot process empty union type"); } + +function isEmptyMixin(i?: Browser.Interface) { + return ( + !!i?.mixin && + isEmptyRecord(i.properties?.property) && + isEmptyRecord(i.methods?.method) && + isEmptyRecord(i.constants?.constant) && + !i.anonymousMethods?.method.length && + !i.events?.event.length + ); +}