Skip to content
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

Add crude dfns patching mechanism #1159

Merged
merged 2 commits into from
Dec 16, 2022
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
2 changes: 2 additions & 0 deletions src/browserlib/extract-dfns.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ export default function (spec, idToHeading = {}) {
return node;
})
.filter(hasValidType)
// Exclude IDL terms defined in a block that is flagged as to be excluded
.filter(node => !node.closest('.exclude'))
// When the whole term links to an external spec, the definition is an
// imported definition. Such definitions are not "real" definitions, let's
// skip them.
Expand Down
3 changes: 2 additions & 1 deletion src/lib/post-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const modules = {
events: require('../postprocessing/events'),
idlnames: require('../postprocessing/idlnames'),
idlparsed: require('../postprocessing/idlparsed'),
annotatelinks: require('../postprocessing/annotate-links')
annotatelinks: require('../postprocessing/annotate-links'),
patchdfns: require('../postprocessing/patch-dfns')
};


Expand Down
40 changes: 40 additions & 0 deletions src/postprocessing/patch-dfns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Post-processing module that can be used to patch definition extracts,
* typically to drop problematic duplicate definitions they may contain.
*
* This post-processing module should only be considered as last resort because
* it requires manual maintenance over time. Goal is to hardcode things here
* only when duplicate terms create actual referencing issues, not to resolve
* all duplicate definitions conflicts.
*
* The module runs at the spec level.
*/

module.exports = {
dependsOn: ['dfns'],
input: 'spec',
property: 'dfns',

run: async function (spec, options) {
// Note the spec object passed to post-processing modules does not contain
// any specific detail on the spec other than the crawled URL, so no direct
// way to match spec on its shortname
if (spec.crawled && spec.dfns) {
// https://github.com/w3c/webref/blob/main/ed/idlpatches/orientation-event.idl.patch
if (spec.crawled.includes('/deviceorientation/') ||
spec.crawled.includes('/TR/orientation-event/')) {
spec.dfns = spec.dfns.filter(dfn =>
!dfn.linkingText.includes('PermissionState') &&
!dfn.for.includes('PermissionState'));
}

// https://github.com/w3c/webref/blob/main/ed/idlpatches/portals.idl.patch
else if (spec.crawled.includes('/portals/')) {
spec.dfns = spec.dfns.filter(dfn =>
dfn.linkingText[0] !== 'MessageEventSource');
}
}

return spec;
}
};