Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
27 changes: 18 additions & 9 deletions src/browserlib/extract-cssdfn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,25 @@ export default function () {
}
if (matchingValues.length === 0) {
// Dangling production rule. That should never happen for properties,
// at-rules, descriptors and functions, since they should always be
// defined somewhere. That happens from time to time for types that are
// described in prose and that don't have a dfn. One could perhaps argue
// that these constructs ought to have a dfn too.
if (!res.warnings) {
res.warnings = []
// at-rules, descriptors: they should always be defined somewhere. That
// happens from time to time for functions and types that are defined
// in a spec and (temporarily) extended in another spec.
if (rule.name.match(/^<.*>$/)) {
const isFunction = !!rule.name.match(/\(\)/);
res.values.push({
name: isFunction ? rule.name.replace(/^<(.*)>$/, '$1') : rule.name,
type: isFunction ? 'function' : 'type',
value: rule.value
});
}
else {
if (!res.warnings) {
res.warnings = [];
}
const warning = Object.assign({ msg: 'Missing definition' }, rule);
warnings.push(warning);
rootDfns.push(warning);
}
const warning = Object.assign({ msg: 'Missing definition' }, rule);
warnings.push(warning);
rootDfns.push(warning);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/postprocessing/cssmerge.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ export default {
baseDfn.syntax = dfn.syntax;
baseDfn.extended = [dfn.spec.crawled ?? dfn.spec.url];
}
else if (dfn.syntax) {
// Extensions of functions and types are *re-definitions* in
// practice, new syntax overrides the base one. There should be
// only one such extension in unrelated specs, the code assumes
// that some sort of curation already took place, and picks up
// a winner randomly.
baseDfn.syntax = dfn.syntax;
}
if (baseDfn.descriptors && dfn.descriptors?.length > 0) {
baseDfn.descriptors.push(...dfn.descriptors.filter(desc =>
!hasNewerDescriptorDfn(desc, dfn, dfns)));
Expand Down
19 changes: 16 additions & 3 deletions test/extract-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,16 +1010,29 @@ that spans multiple lines */
]
},

{
title: 'creates a definition when one is missing for a type',
html: `
<pre class="prod">&lt;my-type> = none | auto</pre>
`,
propertyName: 'values',
css: [{
name: '<my-type>',
type: 'type',
value: 'none | auto'
}]
},

{
title: 'issues a warning when a definition is missing',
html: `
<pre class="prod">&lt;my-type&gt; = none | auto
<pre class="prod">foo = bar</pre>
`,
propertyName: 'warnings',
css: [{
msg: 'Missing definition',
name: '<my-type>',
value: 'none | auto'
name: 'foo',
value: 'bar'
}]
},

Expand Down