Skip to content

Commit 1981a0a

Browse files
authored
Merge branch 'master' into idbrequest
2 parents 064bd03 + 68fe8bb commit 1981a0a

File tree

4 files changed

+86
-23
lines changed

4 files changed

+86
-23
lines changed

baselines/dom.generated.d.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11591,7 +11591,7 @@ declare var SVGCircleElement: {
1159111591
new(): SVGCircleElement;
1159211592
};
1159311593

11594-
interface SVGClipPathElement extends SVGGraphicsElement, SVGUnitTypes {
11594+
interface SVGClipPathElement extends SVGGraphicsElement {
1159511595
readonly clipPathUnits: SVGAnimatedEnumeration;
1159611596
addEventListener<K extends keyof SVGElementEventMap>(type: K, listener: (this: SVGClipPathElement, ev: SVGElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
1159711597
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
@@ -12173,7 +12173,7 @@ declare var SVGFETurbulenceElement: {
1217312173
readonly SVG_TURBULENCE_TYPE_UNKNOWN: number;
1217412174
};
1217512175

12176-
interface SVGFilterElement extends SVGElement, SVGUnitTypes, SVGURIReference {
12176+
interface SVGFilterElement extends SVGElement, SVGURIReference {
1217712177
/** @deprecated */
1217812178
readonly filterResX: SVGAnimatedInteger;
1217912179
/** @deprecated */
@@ -12255,7 +12255,7 @@ declare var SVGGeometryElement: {
1225512255
new(): SVGGeometryElement;
1225612256
};
1225712257

12258-
interface SVGGradientElement extends SVGElement, SVGUnitTypes, SVGURIReference {
12258+
interface SVGGradientElement extends SVGElement, SVGURIReference {
1225912259
readonly gradientTransform: SVGAnimatedTransformList;
1226012260
readonly gradientUnits: SVGAnimatedEnumeration;
1226112261
readonly spreadMethod: SVGAnimatedEnumeration;
@@ -12430,7 +12430,7 @@ declare var SVGMarkerElement: {
1243012430
readonly SVG_MARKER_ORIENT_UNKNOWN: number;
1243112431
};
1243212432

12433-
interface SVGMaskElement extends SVGElement, SVGTests, SVGUnitTypes {
12433+
interface SVGMaskElement extends SVGElement, SVGTests {
1243412434
readonly height: SVGAnimatedLength;
1243512435
readonly maskContentUnits: SVGAnimatedEnumeration;
1243612436
readonly maskUnits: SVGAnimatedEnumeration;
@@ -12819,7 +12819,7 @@ declare var SVGPathSegMovetoRel: {
1281912819
new(): SVGPathSegMovetoRel;
1282012820
};
1282112821

12822-
interface SVGPatternElement extends SVGElement, SVGTests, SVGUnitTypes, SVGFitToViewBox, SVGURIReference {
12822+
interface SVGPatternElement extends SVGElement, SVGTests, SVGFitToViewBox, SVGURIReference {
1282312823
readonly height: SVGAnimatedLength;
1282412824
readonly patternContentUnits: SVGAnimatedEnumeration;
1282512825
readonly patternTransform: SVGAnimatedTransformList;
@@ -13019,6 +13019,9 @@ interface SVGSVGElement extends SVGGraphicsElement, DocumentEvent, SVGFitToViewB
1301913019
declare var SVGSVGElement: {
1302013020
prototype: SVGSVGElement;
1302113021
new(): SVGSVGElement;
13022+
readonly SVG_ZOOMANDPAN_DISABLE: number;
13023+
readonly SVG_ZOOMANDPAN_MAGNIFY: number;
13024+
readonly SVG_ZOOMANDPAN_UNKNOWN: number;
1302213025
};
1302313026

1302413027
interface SVGScriptElement extends SVGElement, SVGURIReference {
@@ -13316,6 +13319,9 @@ interface SVGViewElement extends SVGElement, SVGFitToViewBox, SVGZoomAndPan {
1331613319
declare var SVGViewElement: {
1331713320
prototype: SVGViewElement;
1331813321
new(): SVGViewElement;
13322+
readonly SVG_ZOOMANDPAN_DISABLE: number;
13323+
readonly SVG_ZOOMANDPAN_MAGNIFY: number;
13324+
readonly SVG_ZOOMANDPAN_UNKNOWN: number;
1331913325
};
1332013326

1332113327
interface SVGZoomAndPan {

inputfiles/removedTypes.json

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@
125125
}
126126
}
127127
},
128+
"SVGClipPathElement": {
129+
"implements": [
130+
"SVGUnitTypes"
131+
]
132+
},
128133
"SVGElementInstance": {
129134
"properties": {
130135
"property": {
@@ -137,7 +142,33 @@
137142
}
138143
}
139144
},
145+
"SVGFilterElement": {
146+
"implements": [
147+
"SVGUnitTypes"
148+
]
149+
},
150+
"SVGGradientElement": {
151+
"implements": [
152+
"SVGUnitTypes"
153+
]
154+
},
155+
"SVGMaskElement": {
156+
"implements": [
157+
"SVGUnitTypes"
158+
]
159+
},
160+
"SVGMatrix": null,
161+
"SVGPatternElement": {
162+
"implements": [
163+
"SVGUnitTypes"
164+
]
165+
},
166+
"SVGPoint": null,
167+
"SVGRect": null,
140168
"SVGSVGElement": {
169+
"implements": [
170+
"SVGUnitTypes"
171+
],
141172
"properties": {
142173
"property": {
143174
"onabort": null,
@@ -147,9 +178,11 @@
147178
}
148179
}
149180
},
150-
"SVGMatrix": null,
151-
"SVGPoint": null,
152-
"SVGRect": null,
181+
"SVGViewElement": {
182+
"implements": [
183+
"SVGUnitTypes"
184+
]
185+
},
153186
"WebKitCSSMatrix": null,
154187
"WebKitDirectoryEntry": null,
155188
"WebKitDirectoryReader": null,
@@ -198,9 +231,7 @@
198231
},
199232
"typedefs": {
200233
"typedef": [
201-
{
202-
"new-type": "ArrayBufferView"
203-
}
234+
"ArrayBufferView"
204235
]
205236
}
206237
}

src/emitter.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,15 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
169169
const eventType = eType === "Event" || dependsOn(eType, "Event") ? eType : defaultEventType;
170170
return { name: p.name, eventName, eventType };
171171
}));
172+
173+
const iNameToConstList = arrayToMap(allInterfaces, i => i.name, i =>
174+
!i.constants ? [] : mapToArray(i.constants.constant));
172175

173176
// Map of interface.Name -> List of base interfaces with event handlers
174177
const iNameToEhParents = arrayToMap(allInterfaces, i => i.name, getParentsWithEventHandler);
175178

179+
const iNameToConstParents = arrayToMap(allInterfaces, i => i.name, getParentsWithConstant);
180+
176181
return flavor === Flavor.ES6Iterators ? emitES6DomIterators() : emit();
177182

178183
function getTagNameToElementNameMap() {
@@ -222,10 +227,21 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
222227
}
223228

224229
const iExtends = i.extends && i.extends.replace(/<.*>$/, '');
225-
const extendedParentWithEventHandler = allInterfacesMap[iExtends] && getParentEventHandler(allInterfacesMap[iExtends]) || [];
226-
const implementedParentsWithEventHandler = i.implements ? flatMap(i.implements, i => getParentEventHandler(allInterfacesMap[i])) : [];
230+
const parentWithEventHandler = allInterfacesMap[iExtends] && getParentEventHandler(allInterfacesMap[iExtends]) || [];
231+
const mixinsWithEventHandler = flatMap(i.implements || [], i => getParentEventHandler(allInterfacesMap[i]));
232+
233+
return distinct(parentWithEventHandler.concat(mixinsWithEventHandler));
234+
}
235+
236+
function getParentsWithConstant(i: Browser.Interface) {
237+
function getParentConstant(i: Browser.Interface): Browser.Interface[] {
238+
const hasConst = iNameToConstList[i.name] && iNameToConstList[i.name].length;
239+
return (hasConst ? [i] : []).concat(getParentsWithConstant(i));
240+
}
241+
242+
const mixinsWithConstant = flatMap(i.implements || [], i => getParentConstant(allInterfacesMap[i]));
227243

228-
return distinct(extendedParentWithEventHandler.concat(implementedParentsWithEventHandler));
244+
return distinct(mixinsWithConstant);
229245
}
230246

231247
function getEventTypeInInterface(eName: string, i: Browser.Interface) {
@@ -760,6 +776,11 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
760776
printer.printLine(`prototype: ${i.name};`);
761777
emitConstructorSignature(i);
762778
emitConstants(i);
779+
if (iNameToConstParents[i.name] && iNameToConstParents[i.name].length) {
780+
for (const parent of iNameToConstParents[i.name]) {
781+
emitConstants(parent);
782+
}
783+
}
763784
emitMembers(/*prefix*/ "", EmitScope.StaticOnly, i);
764785

765786
printer.decreaseIndent();

src/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,27 @@ function emitDom() {
113113
emitES6DomIterators(webidl, tsWebIteratorsOutput);
114114

115115
function prune(obj: Browser.WebIdl, template: Partial<Browser.WebIdl>): Browser.WebIdl {
116-
const result = filterByNull(obj, template);
117-
if (obj.typedefs) result.typedefs!.typedef = obj.typedefs.typedef.filter(t => !(template.typedefs && template.typedefs.typedef.find(o => o["new-type"] === t["new-type"])));
118-
119-
return result;
116+
return filterByNull(obj, template);
120117

121118
function filterByNull(obj: any, template: any) {
122119
if (!template) return obj;
123120
const filtered: any = {};
124121
for (const k in obj) {
125-
if (template.hasOwnProperty(k) && !Array.isArray(template[k])) {
126-
if (template[k] !== null) {
127-
filtered[k] = filterByNull(obj[k], template[k]);
122+
if (!template.hasOwnProperty(k)) {
123+
filtered[k] = obj[k];
124+
}
125+
else if (Array.isArray(template[k])) {
126+
if (!Array.isArray(obj[k])) {
127+
throw new Error(`Removal template ${k} is an array but the original field is not`);
128128
}
129+
// template should include strings
130+
filtered[k] = obj[k].filter((item: any) => {
131+
const name = typeof item === "string" ? item : (item.name || item["new-type"]);
132+
return !template[k].includes(name);
133+
});
129134
}
130-
else {
131-
filtered[k] = obj[k];
135+
else if (template[k] !== null) {
136+
filtered[k] = filterByNull(obj[k], template[k]);
132137
}
133138
}
134139
return filtered;

0 commit comments

Comments
 (0)