Skip to content

Inherit const members in constructors #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11591,7 +11591,7 @@ declare var SVGCircleElement: {
new(): SVGCircleElement;
};

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

interface SVGFilterElement extends SVGElement, SVGUnitTypes, SVGURIReference {
interface SVGFilterElement extends SVGElement, SVGURIReference {
/** @deprecated */
readonly filterResX: SVGAnimatedInteger;
/** @deprecated */
Expand Down Expand Up @@ -12255,7 +12255,7 @@ declare var SVGGeometryElement: {
new(): SVGGeometryElement;
};

interface SVGGradientElement extends SVGElement, SVGUnitTypes, SVGURIReference {
interface SVGGradientElement extends SVGElement, SVGURIReference {
readonly gradientTransform: SVGAnimatedTransformList;
readonly gradientUnits: SVGAnimatedEnumeration;
readonly spreadMethod: SVGAnimatedEnumeration;
Expand Down Expand Up @@ -12430,7 +12430,7 @@ declare var SVGMarkerElement: {
readonly SVG_MARKER_ORIENT_UNKNOWN: number;
};

interface SVGMaskElement extends SVGElement, SVGTests, SVGUnitTypes {
interface SVGMaskElement extends SVGElement, SVGTests {
readonly height: SVGAnimatedLength;
readonly maskContentUnits: SVGAnimatedEnumeration;
readonly maskUnits: SVGAnimatedEnumeration;
Expand Down Expand Up @@ -12819,7 +12819,7 @@ declare var SVGPathSegMovetoRel: {
new(): SVGPathSegMovetoRel;
};

interface SVGPatternElement extends SVGElement, SVGTests, SVGUnitTypes, SVGFitToViewBox, SVGURIReference {
interface SVGPatternElement extends SVGElement, SVGTests, SVGFitToViewBox, SVGURIReference {
readonly height: SVGAnimatedLength;
readonly patternContentUnits: SVGAnimatedEnumeration;
readonly patternTransform: SVGAnimatedTransformList;
Expand Down Expand Up @@ -13019,6 +13019,9 @@ interface SVGSVGElement extends SVGGraphicsElement, DocumentEvent, SVGFitToViewB
declare var SVGSVGElement: {
prototype: SVGSVGElement;
new(): SVGSVGElement;
readonly SVG_ZOOMANDPAN_DISABLE: number;
readonly SVG_ZOOMANDPAN_MAGNIFY: number;
readonly SVG_ZOOMANDPAN_UNKNOWN: number;
};

interface SVGScriptElement extends SVGElement, SVGURIReference {
Expand Down Expand Up @@ -13316,6 +13319,9 @@ interface SVGViewElement extends SVGElement, SVGFitToViewBox, SVGZoomAndPan {
declare var SVGViewElement: {
prototype: SVGViewElement;
new(): SVGViewElement;
readonly SVG_ZOOMANDPAN_DISABLE: number;
readonly SVG_ZOOMANDPAN_MAGNIFY: number;
readonly SVG_ZOOMANDPAN_UNKNOWN: number;
};

interface SVGZoomAndPan {
Expand Down
43 changes: 37 additions & 6 deletions inputfiles/removedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
}
}
},
"SVGClipPathElement": {
"implements": [
"SVGUnitTypes"
]
},
"SVGElementInstance": {
"properties": {
"property": {
Expand All @@ -137,7 +142,33 @@
}
}
},
"SVGFilterElement": {
"implements": [
"SVGUnitTypes"
]
},
"SVGGradientElement": {
"implements": [
"SVGUnitTypes"
]
},
"SVGMaskElement": {
"implements": [
"SVGUnitTypes"
]
},
"SVGMatrix": null,
"SVGPatternElement": {
"implements": [
"SVGUnitTypes"
]
},
"SVGPoint": null,
"SVGRect": null,
"SVGSVGElement": {
"implements": [
"SVGUnitTypes"
],
"properties": {
"property": {
"onabort": null,
Expand All @@ -147,9 +178,11 @@
}
}
},
"SVGMatrix": null,
"SVGPoint": null,
"SVGRect": null,
"SVGViewElement": {
"implements": [
"SVGUnitTypes"
]
},
"WebKitCSSMatrix": null,
"WebKitDirectoryEntry": null,
"WebKitDirectoryReader": null,
Expand Down Expand Up @@ -198,9 +231,7 @@
},
"typedefs": {
"typedef": [
{
"new-type": "ArrayBufferView"
}
"ArrayBufferView"
]
}
}
27 changes: 24 additions & 3 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,15 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
const eventType = eType === "Event" || dependsOn(eType, "Event") ? eType : defaultEventType;
return { name: p.name, eventName, eventType };
}));

const iNameToConstList = arrayToMap(allInterfaces, i => i.name, i =>
!i.constants ? [] : mapToArray(i.constants.constant));

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

const iNameToConstParents = arrayToMap(allInterfaces, i => i.name, getParentsWithConstant);

return flavor === Flavor.ES6Iterators ? emitES6DomIterators() : emit();

function getTagNameToElementNameMap() {
Expand Down Expand Up @@ -221,10 +226,21 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
return ehParents;
}

const extendedParentWithEventHandler = allInterfacesMap[i.extends] && getParentEventHandler(allInterfacesMap[i.extends]) || [];
const implementedParentsWithEventHandler = i.implements ? flatMap(i.implements, i => getParentEventHandler(allInterfacesMap[i])) : [];
const parentWithEventHandler = allInterfacesMap[i.extends] && getParentEventHandler(allInterfacesMap[i.extends]) || [];
const mixinsWithEventHandler = flatMap(i.implements || [], i => getParentEventHandler(allInterfacesMap[i]));

return distinct(parentWithEventHandler.concat(mixinsWithEventHandler));
}

function getParentsWithConstant(i: Browser.Interface) {
function getParentConstant(i: Browser.Interface): Browser.Interface[] {
const hasConst = iNameToConstList[i.name] && iNameToConstList[i.name].length;
return (hasConst ? [i] : []).concat(getParentsWithConstant(i));
}

const mixinsWithConstant = flatMap(i.implements || [], i => getParentConstant(allInterfacesMap[i]));

return distinct(extendedParentWithEventHandler.concat(implementedParentsWithEventHandler));
return distinct(mixinsWithConstant);
}

function getEventTypeInInterface(eName: string, i: Browser.Interface) {
Expand Down Expand Up @@ -746,6 +762,11 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
printer.printLine(`prototype: ${i.name};`);
emitConstructorSignature(i);
emitConstants(i);
if (iNameToConstParents[i.name] && iNameToConstParents[i.name].length) {
for (const parent of iNameToConstParents[i.name]) {
emitConstants(parent);
}
}
emitMembers(/*prefix*/ "", EmitScope.StaticOnly, i);

printer.decreaseIndent();
Expand Down
23 changes: 14 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,27 @@ function emitDom() {
emitES6DomIterators(webidl, tsWebIteratorsOutput);

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

return result;
return filterByNull(obj, template);

function filterByNull(obj: any, template: any) {
if (!template) return obj;
const filtered: any = {};
for (const k in obj) {
if (template.hasOwnProperty(k) && !Array.isArray(template[k])) {
if (template[k] !== null) {
filtered[k] = filterByNull(obj[k], template[k]);
if (!template.hasOwnProperty(k)) {
filtered[k] = obj[k];
}
else if (Array.isArray(template[k])) {
if (!Array.isArray(obj[k])) {
throw new Error(`Removal template ${k} is an array but the original field is not`);
}
// template should include strings
filtered[k] = obj[k].filter((item: any) => {
const name = typeof item === "string" ? item : (item.name || item["new-type"]);
return !template[k].includes(name);
});
}
else {
filtered[k] = obj[k];
else if (template[k] !== null) {
filtered[k] = filterByNull(obj[k], template[k]);
}
}
return filtered;
Expand Down