Skip to content

Commit

Permalink
Automatically trim redundant mixins (#1399)
Browse files Browse the repository at this point in the history
Co-authored-by: saschanaz <saschanaz@users.noreply.github.com>
  • Loading branch information
saschanaz and saschanaz committed Sep 17, 2022
1 parent f89d4cf commit c0095a3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 42 deletions.
49 changes: 13 additions & 36 deletions inputfiles/removedTypes.jsonc
Expand Up @@ -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": {
Expand All @@ -91,9 +73,6 @@
}
}
},
"SVGElement": {
"implements": ["SVGElementInstance"]
},
"SVGFEGaussianBlurElement": {
"constants": {
"constant": {
Expand All @@ -104,9 +83,6 @@
}
}
},
"Text": {
"implements": ["GeometryUtils"]
},
"WebGLBuffer": {
"extends": null
},
Expand Down Expand Up @@ -142,17 +118,6 @@
},
"WebGLVertexArrayObjectOES": {
"extends": null
},
"WorkerNavigator": {
"implements": [
"NavigatorBadge",
"NavigatorDeviceMemory",
"NavigatorFonts",
"NavigatorGPU",
"NavigatorML",
"NavigatorNetworkInformation",
"NavigatorUA"
]
}
}
},
Expand Down Expand Up @@ -576,6 +541,18 @@
}
}
},
"mixins": {
"mixin":{
"NavigatorNetworkInformation": {
"properties": {
"property": {
// https://github.com/mdn/browser-compat-data/pull/17824
"connection": null
}
}
}
}
},
"typedefs": {
"typedef": [
"ArrayBufferView"
Expand Down
5 changes: 3 additions & 2 deletions src/build/bcd.ts
Expand Up @@ -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;
}
Expand Down
34 changes: 30 additions & 4 deletions src/build/expose.ts
Expand Up @@ -8,6 +8,7 @@ import {
mapToArray,
arrayToMap,
} from "./helpers.js";
import { isEmptyRecord } from "./utils/record.js";

class LoggedSet extends Set<string> {
private unvisited: Set<string>;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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})`);
Expand Down Expand Up @@ -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
);
}

0 comments on commit c0095a3

Please sign in to comment.