Skip to content

Commit e7bcbdc

Browse files
authored
Events post-processor: consolidate events that "babble" (#1546)
It seems possible to end up with events that bubble for some target interfaces but don't for other target interfaces, see discussion in: w3c/webref#1212 The post-processor already knew how to assign a bubbling flag per target interface because we make a distinction between interfaces that are in a bubbling tree and interfaces that are not. However, the post-processor did not know how to consolidate an entry that appears duplicated in the events extract because the underlying event bubbles in one case but not in the other. This update makes it able to consolidate these events (which I call "babbling" events because, hey, it's Friday evening). We still don't have post-processing tests but that seems to work fine on Webref data.
1 parent 915508d commit e7bcbdc

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/postprocessing/events.js

+34
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ module.exports = {
6565
})
6666
.filter(event => !!event);
6767

68+
// Before we clean and sort the result, we'll consolidate events that
69+
// don't always bubble. We'll call them... "babbling" events. Such events
70+
// should remain exceptions to the rule, and will likely be artificially
71+
// created through some patching mechanism (in Webref typically) because
72+
// the events extraction logic does not (yet?) support this scenario.
6873
return events
6974
.filter(event => !eventsToDrop.includes(event))
75+
.filter(event => consolidateBabblingEvent(event, events))
7076
.map(event => {
7177
cleanTargetInterfaces(event, parsedInterfaces);
7278
delete event.spec;
@@ -223,3 +229,31 @@ function extendEvent(event, events) {
223229
{ spec: event.spec.series.shortname },
224230
event.src?.href ? { href: event.src?.href } : {}));
225231
}
232+
233+
234+
/**
235+
* Consolidate events that got duplicated in the extract because they bubble
236+
* or don't bubble depending on the target interface.
237+
*
238+
* We'll say that these events "babble" because they don't seem to know whether
239+
* they bubble or not.
240+
*/
241+
function consolidateBabblingEvent(event, events) {
242+
if (event.mergedIntoAnotherEvent) {
243+
return null;
244+
}
245+
const newTargets = events
246+
.filter(e =>
247+
e !== event && !e.isExtension && !e.mergedIntoAnotherEvent &&
248+
e.href && e.href === event.href && e.cancelable === event.cancelable)
249+
.map(e => {
250+
// Flag the event as merged so that we can filter it out afterwards
251+
e.mergedIntoAnotherEvent = true;
252+
return e.targets;
253+
})
254+
.flat();
255+
if (newTargets.length > 0) {
256+
event.targets = (event.targets || []).concat(newTargets);
257+
}
258+
return event;
259+
}

0 commit comments

Comments
 (0)