Skip to content

Commit 7162786

Browse files
author
Orta Therox
authored
Merge pull request #1081 from saschanaz/idl-mapper
Use bcd-idl-mapper
2 parents 0da683b + a75ebb5 commit 7162786

File tree

7 files changed

+109
-185
lines changed

7 files changed

+109
-185
lines changed

baselines/dom.generated.d.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,7 @@ interface CSSStyleDeclaration {
27622762
captionSide: string;
27632763
caretColor: string;
27642764
clear: string;
2765+
/** @deprecated */
27652766
clip: string;
27662767
clipPath: string;
27672768
clipRule: string;
@@ -2816,6 +2817,7 @@ interface CSSStyleDeclaration {
28162817
fontStyle: string;
28172818
fontSynthesis: string;
28182819
fontVariant: string;
2820+
/** @deprecated */
28192821
fontVariantAlternates: string;
28202822
fontVariantCaps: string;
28212823
fontVariantEastAsian: string;
@@ -3124,7 +3126,6 @@ interface CSSStyleDeclaration {
31243126
webkitMaskBoxImageWidth: string;
31253127
/** @deprecated */
31263128
webkitMaskClip: string;
3127-
/** @deprecated */
31283129
webkitMaskComposite: string;
31293130
/** @deprecated */
31303131
webkitMaskImage: string;
@@ -3142,15 +3143,9 @@ interface CSSStyleDeclaration {
31423143
webkitPerspective: string;
31433144
/** @deprecated */
31443145
webkitPerspectiveOrigin: string;
3145-
/** @deprecated */
31463146
webkitTextFillColor: string;
3147-
/** @deprecated */
3148-
webkitTextSizeAdjust: string;
3149-
/** @deprecated */
31503147
webkitTextStroke: string;
3151-
/** @deprecated */
31523148
webkitTextStrokeColor: string;
3153-
/** @deprecated */
31543149
webkitTextStrokeWidth: string;
31553150
/** @deprecated */
31563151
webkitTransform: string;
@@ -17186,6 +17181,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
1718617181
/** A window containing a DOM document; the document property points to the DOM document loaded in that window. */
1718717182
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
1718817183
HTMLDocument: Document;
17184+
readonly clientInformation: Navigator;
1718917185
/**
1719017186
* Returns true if the window has been closed, false otherwise.
1719117187
*/
@@ -18246,6 +18242,7 @@ declare var Option: {
1824618242
new(text?: string, value?: string, defaultSelected?: boolean, selected?: boolean): HTMLOptionElement;
1824718243
};
1824818244
declare var HTMLDocument: Document;
18245+
declare var clientInformation: Navigator;
1824918246
/**
1825018247
* Returns true if the window has been closed, false otherwise.
1825118248
*/

package-lock.json

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@
3939
"license": "Apache-2.0",
4040
"type": "module",
4141
"devDependencies": {
42-
"@mdn/browser-compat-data": "^3.3.9",
43-
"@types/jsdom": "^16.2.12",
44-
"@types/node": "^15.14.1",
45-
"@types/node-fetch": "^2.5.10",
46-
"@types/webidl2": "^23.13.5",
47-
"@typescript-eslint/eslint-plugin": "^4.28.1",
48-
"@typescript-eslint/parser": "^4.28.1",
49-
"@webref/css": "^2.0.2",
50-
"@webref/elements": "^1.0.1",
51-
"@webref/idl": "^2.2.6",
42+
"@mdn/browser-compat-data": "^3.3.13",
43+
"@types/jsdom": "^16.2.13",
44+
"@types/node": "^16.4.8",
45+
"@types/node-fetch": "^2.5.12",
46+
"@types/webidl2": "^23.13.6",
47+
"@typescript-eslint/eslint-plugin": "^4.28.5",
48+
"@typescript-eslint/parser": "^4.28.5",
49+
"@webref/css": "^2.0.5",
50+
"@webref/elements": "^1.0.2",
51+
"@webref/idl": "^2.2.9",
52+
"bcd-idl-mapper": "^1.1.1",
5253
"cpx2": "^3.0.0",
5354
"danger": "^10.6.6",
54-
"eslint": "^7.29.0",
55+
"eslint": "^7.32.0",
5556
"eslint-config-prettier": "^8.3.0",
5657
"eslint-plugin-prettier": "^3.4.0",
5758
"jsdom": "^16.6.0",

src/build/bcd.ts

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import * as Browser from "./types";
2-
import bcd from "@mdn/browser-compat-data";
32
import {
43
CompatStatement,
54
SimpleSupportStatement,
65
SupportBlock,
76
} from "@mdn/browser-compat-data/types";
8-
import { camelToHyphenCase } from "./utils/css.js";
97
import { forceKeepAlive } from "./bcd/keep-alive.js";
108
import { mapToBcdCompat } from "./bcd/mapper.js";
119
import { hasStableImplementation } from "./bcd/stable.js";
@@ -53,37 +51,6 @@ function isSuitable(
5351
}
5452

5553
export function getRemovalData(webidl: Browser.WebIdl): Browser.WebIdl {
56-
const CSSStyleDeclarationKey = "CSSStyleDeclaration";
57-
58-
function shouldStyleBeRemoved(key: string) {
59-
const hyphenCase = camelToHyphenCase(key);
60-
const bcdCssItem = bcd.css.properties[hyphenCase];
61-
if (
62-
bcdCssItem &&
63-
isSuitable(hyphenCase, bcdCssItem.__compat, CSSStyleDeclarationKey)
64-
) {
65-
return false;
66-
}
67-
if (hyphenCase.startsWith("-webkit-")) {
68-
const noPrefix = hyphenCase.slice(8);
69-
const bcdWebKitItem = bcd.css.properties[noPrefix];
70-
if (
71-
bcdWebKitItem &&
72-
isSuitable(
73-
noPrefix,
74-
bcdWebKitItem.__compat,
75-
CSSStyleDeclarationKey,
76-
"-webkit-"
77-
)
78-
) {
79-
return false;
80-
}
81-
} else if (forceKeepAlive[CSSStyleDeclarationKey]?.includes(key)) {
82-
return false;
83-
}
84-
return true;
85-
}
86-
8754
return mapToBcdCompat(webidl, ({ key, parentKey, compat, mixin }) => {
8855
// Allow all mixins for now, but not their members
8956
// Ultimately expose.ts should be updated to check empty mixins
@@ -93,19 +60,15 @@ export function getRemovalData(webidl: Browser.WebIdl): Browser.WebIdl {
9360
if (isSuitable(key, compat, parentKey)) {
9461
return;
9562
}
96-
if (parentKey === CSSStyleDeclarationKey && !shouldStyleBeRemoved(key)) {
97-
return;
98-
}
9963
return { exposed: "" };
10064
}) as Browser.WebIdl;
10165
}
10266

10367
export function getDeprecationData(webidl: Browser.WebIdl): Browser.WebIdl {
104-
const webkitExceptions = ["webkitLineClamp"];
105-
return mapToBcdCompat(webidl, ({ key, compat, webkit }) => {
68+
return mapToBcdCompat(webidl, ({ key, compat }) => {
10669
if (
10770
compat?.status?.deprecated ||
108-
(!compat && webkit && !webkitExceptions.includes(key))
71+
(compat?.status?.preferred_name && key.startsWith("webkit"))
10972
) {
11073
return { deprecated: 1 };
11174
}

src/build/bcd/keep-alive.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,26 @@ export const forceKeepAlive: Record<string, string[]> = {
33
// These should be filed to https://github.com/mdn/browser-compat-data/issues
44
console: ["profile", "profileEnd", "timeStamp"],
55
CSSStyleDeclaration: [
6-
"alignContent",
7-
"alignItems",
8-
"alignSelf",
96
"alignmentBaseline",
107
"baselineShift",
11-
"breakAfter",
12-
"breakBefore",
13-
"breakInside",
148
"clipRule",
159
"colorInterpolation",
1610
"colorInterpolationFilters",
17-
"columnGap",
1811
"dominantBaseline",
1912
"fill",
2013
"fillOpacity",
2114
"fillRule",
2215
"floodColor",
2316
"floodOpacity",
2417
"fontSizeAdjust",
25-
"fontVariantPosition",
26-
"gap",
2718
"gridColumnGap",
2819
"gridGap",
2920
"gridRowGap",
30-
"justifyContent",
31-
"justifyItems",
32-
"justifySelf",
3321
"lightingColor",
3422
"marker",
3523
"markerEnd",
3624
"markerMid",
3725
"markerStart",
38-
"placeContent",
39-
"placeItems",
40-
"placeSelf",
41-
"rotate",
42-
"rowGap",
43-
"scale",
4426
"shapeRendering",
4527
"stopColor",
4628
"stopOpacity",
@@ -53,21 +35,8 @@ export const forceKeepAlive: Record<string, string[]> = {
5335
"strokeOpacity",
5436
"strokeWidth",
5537
"textAnchor",
56-
"translate",
57-
"webkitAlignContent",
58-
"webkitAlignItems",
59-
"webkitAlignSelf",
60-
"webkitJustifyContent",
61-
"webkitMaskBoxImageOutset",
62-
"webkitMaskBoxImageRepeat",
63-
"webkitMaskBoxImageSlice",
64-
"webkitMaskBoxImageSource",
65-
"webkitMaskBoxImageWidth",
66-
"wordWrap", // TODO: Support for alternative names
6738
],
6839
DOMRect: ["x", "y", "width", "height"],
69-
Document: ["charset", "inputEncoding"],
70-
Element: ["webkitMatchesSelector"],
7140
Gamepad: ["hapticActuators"],
7241
GlobalEventHandlers: [
7342
"ontoggle",

src/build/bcd/mapper.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { CompatData, CompatStatement } from "@mdn/browser-compat-data/types";
1+
import {
2+
CompatStatement,
3+
Identifier,
4+
SimpleSupportStatement,
5+
} from "bcd-idl-mapper";
6+
import api from "bcd-idl-mapper";
27
import * as Browser from "../types";
38
import { filterMapRecord, isEmptyRecord } from "../utils/record.js";
49
import { mapDefined } from "../helpers.js";
5-
import resolveMixinSupportData from "./resolve-mixin.js";
10+
import { hasStableImplementation } from "./stable.js";
611

712
interface DataToMap {
813
key: string;
@@ -12,15 +17,47 @@ interface DataToMap {
1217
parentKey?: string;
1318
}
1419

20+
function mergeCompatStatements(data?: Identifier): CompatStatement | undefined {
21+
if (!data) {
22+
return;
23+
}
24+
if (data?.__compat) {
25+
return data.__compat;
26+
}
27+
28+
// Some items have no top level __compat and instead have contexts with compat data for each
29+
30+
const statements = Object.values(data)
31+
.map((d) => d.__compat)
32+
.filter((n) => n) as CompatStatement[];
33+
34+
const base = Object.fromEntries(
35+
Object.keys(statements[0].support).map((key) => {
36+
return [key, [] as SimpleSupportStatement[]];
37+
})
38+
);
39+
40+
for (const statement of statements) {
41+
for (const key of Object.keys(statement.support)) {
42+
const support = statement.support[key];
43+
if (support && hasStableImplementation(support)) {
44+
base[key].push(...(Array.isArray(support) ? support : [support]));
45+
}
46+
}
47+
}
48+
49+
return { ...statements[0], support: base };
50+
}
51+
1552
function mapInterfaceLike(
1653
name: string,
1754
i: Browser.Interface,
18-
bcdResolved: CompatData,
1955
mapper: (data: DataToMap) => any
2056
) {
21-
const intCompat = bcdResolved.api[name]?.__compat;
57+
const data = i.mixin ? api.__mixins[name] : api[name];
58+
const intCompat = data?.__compat;
2259
const mapped = mapper({ key: name, compat: intCompat, mixin: !!i.mixin });
23-
if (!intCompat) {
60+
if (!data) {
2461
if (mapped) {
2562
return { name: i.name, ...mapped };
2663
}
@@ -29,11 +66,10 @@ function mapInterfaceLike(
2966
const result = { ...mapped };
3067

3168
const recordMapper = (key: string) => {
32-
const compat = bcdResolved.api[name][key]?.__compat;
69+
const compat = mergeCompatStatements(data[key]);
3370
return mapper({
3471
key,
3572
parentKey: name,
36-
webkit: key.startsWith("webkit"),
3773
compat,
3874
mixin: !!i.mixin,
3975
});
@@ -55,14 +91,13 @@ export function mapToBcdCompat(
5591
webidl: Browser.WebIdl,
5692
mapper: (data: DataToMap) => any
5793
): Browser.WebIdl | undefined {
58-
const bcdResolved = resolveMixinSupportData(webidl);
5994
const map = (name: string, i: Browser.Interface) =>
60-
mapInterfaceLike(name, i, bcdResolved, mapper);
95+
mapInterfaceLike(name, i, mapper);
6196

6297
const interfaces = filterMapRecord(webidl.interfaces?.interface, map);
6398
const mixins = filterMapRecord(webidl.mixins?.mixin, map);
6499
const namespaces = mapDefined(webidl.namespaces, (n) =>
65-
mapInterfaceLike(n.name, n, bcdResolved, mapper)
100+
mapInterfaceLike(n.name, n, mapper)
66101
);
67102
if (
68103
!isEmptyRecord(interfaces) ||

0 commit comments

Comments
 (0)