Skip to content

Commit da12590

Browse files
committed
feat(bcd): resolve compat data for mixin members
Closes microsoft#9, closes microsoft#10
1 parent 87dd612 commit da12590

File tree

7 files changed

+173
-118
lines changed

7 files changed

+173
-118
lines changed

baselines/dom.generated.d.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,6 @@ interface CanvasShadowStyles {
34053405
}
34063406

34073407
interface CanvasState {
3408-
reset(): void;
34093408
restore(): void;
34103409
save(): void;
34113410
}
@@ -3419,14 +3418,8 @@ interface CanvasText {
34193418
interface CanvasTextDrawingStyles {
34203419
direction: CanvasDirection;
34213420
font: string;
3422-
fontKerning: CanvasFontKerning;
3423-
fontStretch: CanvasFontStretch;
3424-
fontVariantCaps: CanvasFontVariantCaps;
34253421
textAlign: CanvasTextAlign;
34263422
textBaseline: CanvasTextBaseline;
3427-
textLetterSpacing: number;
3428-
textRendering: CanvasTextRendering;
3429-
textWordSpacing: number;
34303423
}
34313424

34323425
interface CanvasTransform {
@@ -3443,8 +3436,6 @@ interface CanvasTransform {
34433436
interface CanvasUserInterface {
34443437
drawFocusIfNeeded(element: Element): void;
34453438
drawFocusIfNeeded(path: Path2D, element: Element): void;
3446-
scrollPathIntoView(): void;
3447-
scrollPathIntoView(path: Path2D): void;
34483439
}
34493440

34503441
/** The ChannelMergerNode interface, often used in conjunction with its opposite, ChannelSplitterNode, reunites different mono inputs into a single output. Each input is used to fill a channel of the output. This is useful for accessing each channels separately, e.g. for performing channel mixing where gain must be separately controlled on each channel. */
@@ -5825,7 +5816,6 @@ interface GlobalEventHandlers {
58255816
* @param ev The event.
58265817
*/
58275818
onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
5828-
onsecuritypolicyviolation: ((this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any) | null;
58295819
/**
58305820
* Occurs when the seek operation ends.
58315821
* @param ev The event.
@@ -7810,7 +7800,6 @@ declare var HTMLOptionsCollection: {
78107800
};
78117801

78127802
interface HTMLOrSVGElement {
7813-
autofocus: boolean;
78147803
readonly dataset: DOMStringMap;
78157804
nonce?: string;
78167805
tabIndex: number;
@@ -10298,7 +10287,6 @@ interface NavigatorConcurrentHardware {
1029810287

1029910288
interface NavigatorContentUtils {
1030010289
registerProtocolHandler(scheme: string, url: string | URL): void;
10301-
unregisterProtocolHandler(scheme: string, url: string | URL): void;
1030210290
}
1030310291

1030410292
interface NavigatorCookies {
@@ -10316,9 +10304,11 @@ interface NavigatorID {
1031610304
readonly platform: string;
1031710305
/** @deprecated */
1031810306
readonly product: string;
10307+
/** @deprecated */
1031910308
readonly productSub: string;
1032010309
readonly userAgent: string;
1032110310
readonly vendor: string;
10311+
/** @deprecated */
1032210312
readonly vendorSub: string;
1032310313
}
1032410314

@@ -18455,7 +18445,6 @@ declare var onresize: ((this: Window, ev: UIEvent) => any) | null;
1845518445
* @param ev The event.
1845618446
*/
1845718447
declare var onscroll: ((this: Window, ev: Event) => any) | null;
18458-
declare var onsecuritypolicyviolation: ((this: Window, ev: SecurityPolicyViolationEvent) => any) | null;
1845918448
/**
1846018449
* Occurs when the seek operation ends.
1846118450
* @param ev The event.

inputfiles/removedTypes.json

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,73 +13,11 @@
1313
},
1414
"mixins": {
1515
"mixin": {
16-
"ARIAMixin": {
17-
"properties": {
18-
"property": {
19-
"ariaColIndexText": null,
20-
"ariaDescription": null,
21-
"ariaInvalid": null,
22-
"ariaRowIndexText": null,
23-
"role": null
24-
}
25-
}
26-
},
27-
"DocumentOrShadowRoot": {
28-
"properties": {
29-
"property": {
30-
"adoptedStyleSheets": null
31-
}
32-
}
33-
},
34-
"ElementCSSInlineStyle": {
35-
"properties": {
36-
"property": {
37-
"attributeStyleMap": null
38-
}
39-
}
40-
},
41-
"GlobalEventHandlers": {
42-
"properties": {
43-
"property": {
44-
"onbeforexrselect": null,
45-
"onpointerrawupdate": null,
46-
"onslotchange": null
47-
}
48-
}
49-
},
50-
"NavigatorID": {
51-
"properties": {
52-
"property": {
53-
"oscpu": null
54-
}
55-
}
56-
},
5716
"WebGLRenderingContextBase": {
5817
"properties": {
5918
"namesakes": {
6019
"canvas": null
6120
}
62-
},
63-
"methods": {
64-
"method": {
65-
"makeXRCompatible": null
66-
}
67-
}
68-
},
69-
"WindowEventHandlers": {
70-
"properties": {
71-
"property": {
72-
"onportalactivate": null
73-
}
74-
}
75-
},
76-
"WindowOrWorkerGlobalScope": {
77-
"properties": {
78-
"property": {
79-
"originPolicyIds": null,
80-
"scheduler": null,
81-
"trustedTypes": null
82-
}
8321
}
8422
}
8523
}

src/build/bcd.ts

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,23 @@ import {
88
import { camelToHyphenCase } from "./utils/css.js";
99
import { forceKeepAlive } from "./bcd/keep-alive.js";
1010
import { mapToBcdCompat } from "./bcd/mapper.js";
11+
import { hasStableImplementation } from "./bcd/stable.js";
1112

1213
function hasMultipleImplementations(support: SupportBlock, prefix?: string) {
13-
function hasStableImplementation(
14+
const hasStableImpl = (
1415
browser: SimpleSupportStatement | SimpleSupportStatement[] | undefined
15-
) {
16-
if (!browser) {
17-
return false;
18-
}
19-
const latest = !Array.isArray(browser)
20-
? browser
21-
: browser.find((i) => i.prefix === prefix); // first one if no prefix
22-
if (!latest) {
23-
return false;
24-
}
25-
return (
26-
latest.version_added &&
27-
!latest.version_removed &&
28-
!latest.flags &&
29-
latest.prefix === prefix &&
30-
!latest.alternative_name
31-
);
32-
}
16+
) => hasStableImplementation(browser, prefix);
3317
let count = 0;
34-
if (
35-
hasStableImplementation(support.chrome) ||
36-
hasStableImplementation(support.chrome_android)
37-
) {
18+
if (hasStableImpl(support.chrome) || hasStableImpl(support.chrome_android)) {
3819
count += 1;
3920
}
4021
if (
41-
hasStableImplementation(support.firefox) ||
42-
hasStableImplementation(support.firefox_android)
22+
hasStableImpl(support.firefox) ||
23+
hasStableImpl(support.firefox_android)
4324
) {
4425
count += 1;
4526
}
46-
if (
47-
hasStableImplementation(support.safari) ||
48-
hasStableImplementation(support.safari_ios)
49-
) {
27+
if (hasStableImpl(support.safari) || hasStableImpl(support.safari_ios)) {
5028
count += 1;
5129
}
5230
return count >= 2;
@@ -107,20 +85,17 @@ export function getRemovalData(webidl: Browser.WebIdl): Browser.WebIdl {
10785
}
10886

10987
return mapToBcdCompat(webidl, ({ key, parentKey, compat, mixin }) => {
110-
// Allow:
111-
// * all mixins, for now
112-
// * mixin members that has no compat data
113-
if (mixin && (!compat || !parentKey)) {
88+
// Allow all mixins for now, but not their members
89+
// Ultimately expose.ts should be updated to check empty mixins
90+
if (mixin && !parentKey) {
11491
return;
11592
}
11693
if (isSuitable(key, compat, parentKey)) {
11794
return;
11895
}
119-
12096
if (parentKey === CSSStyleDeclarationKey && !shouldStyleBeRemoved(key)) {
12197
return;
12298
}
123-
12499
return { exposed: "" };
125100
}) as Browser.WebIdl;
126101
}

src/build/bcd/keep-alive.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ export const forceKeepAlive: Record<string, string[]> = {
101101
ExtendableMessageEvent: ["lastEventId", "origin", "ports", "source"],
102102
FileReader: ["onloadstart"],
103103
Gamepad: ["hapticActuators"],
104+
GlobalEventHandlers: [
105+
"ontoggle",
106+
"onwebkitanimationend",
107+
"onwebkitanimationiteration",
108+
"onwebkitanimationstart",
109+
"onwebkittransitionend",
110+
],
104111
HTMLIFrameElement: ["allowPaymentRequest"],
105112
KeyframeEffect: ["iterationComposite"],
106113
LinkStyle: ["sheet"],
@@ -125,13 +132,17 @@ export const forceKeepAlive: Record<string, string[]> = {
125132
"autoPictureInPicture",
126133
"disablePictureInPicture",
127134
],
135+
ReadableStreamGenericReader: ["closed", "cancel"],
128136
Request: ["keepalive"],
129137
ResizeObserverSize: ["blockSize", "inlineSize"],
130138
RTCDtlsTransport: ["onstatechange", "state"],
131139
RTCPeerConnection: ["canTrickleIceCandidates"],
132140
ServiceWorkerGlobalScope: ["onmessageerror"],
141+
SVGAnimatedPoints: ["animatedPoints", "points"],
133142
SVGAnimatedTransformList: ["animVal", "baseVal"],
134143
SVGElement: ["ownerSVGElement", "viewportElement"],
144+
SVGFilterPrimitiveStandardAttributes: ["height", "result", "width", "x", "y"],
145+
SVGTests: ["requiredExtensions", "systemLanguage"],
135146
SVGTransformList: [
136147
"numberOfItems",
137148
"appendItem",
@@ -152,7 +163,32 @@ export const forceKeepAlive: Record<string, string[]> = {
152163
"instantiateStreaming",
153164
"validate",
154165
],
155-
WindowEventHandlers: ["onmessage"],
166+
WebGLRenderingContextBase: ["lineWidth"],
167+
WebGL2RenderingContextOverloads: [
168+
// These are implemented in WebGLRenderingContext and WebGL2RenderingContext separately
169+
// but BCD only have them in WebGLRenderingContext
170+
"bufferData",
171+
"compressedTexImage2D",
172+
"compressedTexSubImage2D",
173+
"readPixels",
174+
"texImage2D",
175+
"texSubImage2D",
176+
"uniform1fv",
177+
"uniform1iv",
178+
"uniform2fv",
179+
"uniform2iv",
180+
"uniform3fv",
181+
"uniform3iv",
182+
"uniform4fv",
183+
"uniform4iv",
184+
],
185+
WindowEventHandlers: [
186+
"onmessage",
187+
"onoffline",
188+
"ononline",
189+
"onpagehide",
190+
"onpageshow",
191+
],
156192
WorkerGlobalScope: ["onrejectionhandled", "onunhandledrejection"],
157193
WorkletGlobalScope: [],
158194
// (WebAssembly namespace members)
@@ -164,7 +200,7 @@ export const forceKeepAlive: Record<string, string[]> = {
164200
Table: ["length", "get", "grow", "set"],
165201

166202
// Widely supported but without being correctly exposed to global
167-
ReadableStreamDefaultReader: ["closed", "cancel", "read", "releaseLock"],
203+
ReadableStreamDefaultReader: ["read", "releaseLock"],
168204
ReadableStreamDefaultController: ["desiredSize", "close", "enqueue", "error"],
169205
WebGLVertexArrayObjectOES: [],
170206
WritableStreamDefaultController: ["error"],

src/build/bcd/mapper.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { CompatStatement } from "@mdn/browser-compat-data/types";
1+
import { CompatData, CompatStatement } from "@mdn/browser-compat-data/types";
22
import * as Browser from "../types";
33
import { filterMapRecord, isEmptyRecord } from "../utils/record.js";
44
import { mapDefined } from "../helpers.js";
5-
import bcd from "@mdn/browser-compat-data";
5+
import resolveMixinSupportData from "./resolve-mixin.js";
66

77
interface DataToMap {
88
key: string;
@@ -15,9 +15,10 @@ interface DataToMap {
1515
function mapInterfaceLike(
1616
name: string,
1717
i: Browser.Interface,
18+
bcdResolved: CompatData,
1819
mapper: (data: DataToMap) => any
1920
) {
20-
const intCompat = bcd.api[name]?.__compat;
21+
const intCompat = bcdResolved.api[name]?.__compat;
2122
const mapped = mapper({ key: name, compat: intCompat, mixin: !!i.mixin });
2223
if (!intCompat) {
2324
if (mapped) {
@@ -28,7 +29,7 @@ function mapInterfaceLike(
2829
const result = { ...mapped };
2930

3031
const recordMapper = (key: string) => {
31-
const compat = bcd.api[name][key]?.__compat;
32+
const compat = bcdResolved.api[name][key]?.__compat;
3233
return mapper({
3334
key,
3435
parentKey: name,
@@ -54,13 +55,14 @@ export function mapToBcdCompat(
5455
webidl: Browser.WebIdl,
5556
mapper: (data: DataToMap) => any
5657
): Browser.WebIdl | undefined {
58+
const bcdResolved = resolveMixinSupportData(webidl);
5759
const map = (name: string, i: Browser.Interface) =>
58-
mapInterfaceLike(name, i, mapper);
60+
mapInterfaceLike(name, i, bcdResolved, mapper);
5961

6062
const interfaces = filterMapRecord(webidl.interfaces?.interface, map);
6163
const mixins = filterMapRecord(webidl.mixins?.mixin, map);
6264
const namespaces = mapDefined(webidl.namespaces, (n) =>
63-
mapInterfaceLike(n.name, n, mapper)
65+
mapInterfaceLike(n.name, n, bcdResolved, mapper)
6466
);
6567
if (
6668
!isEmptyRecord(interfaces) ||

0 commit comments

Comments
 (0)