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

[css extraction] Handle subsidiary at-rules #1377

Merged
merged 1 commit into from
Sep 25, 2023
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
15 changes: 13 additions & 2 deletions src/browserlib/extract-cssdfn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function () {
// Note some selectors are re-defined locally in HTML and Fullscreen. We
// won't import them.
atrules: extractDfns({
selector: 'dfn[data-dfn-type=at-rule]',
selector: 'dfn[data-dfn-type=at-rule]:not([data-dfn-for])',
extractor: extractTypedDfn,
duplicates: 'reject',
warnings
Expand Down Expand Up @@ -90,7 +90,18 @@ export default function () {
});
}

// Move descriptors to at-rules structure
// Subsidiary at-rules are at-rules that can be used within a parent at-rule,
// we'll consider that they are "descriptors".
const subsidiary = extractDfns({
selector: 'dfn[data-dfn-type=at-rule][data-dfn-for]',
extractor: extractTypedDfn,
duplicates: 'reject',
keepDfnType: true,
warnings
});
descriptors = descriptors.concat([subsidiary]);

// Move descriptors, and subsidiary at-rules, to at-rules structure
for (const desclist of descriptors) {
for (const desc of desclist) {
let rule = res.atrules.find(r => r.name === desc.for);
Expand Down
28 changes: 28 additions & 0 deletions tests/extract-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,34 @@ const tests = [
},


{
title: "understands subsidiary at-rules",
html: `
<pre class="prod">
@font-feature-values = &lt;family-name&gt;# { &lt;declaration-rule-list&gt; }
</pre>
<p><dfn data-dfn-type="at-rule" data-export="" id="at-ruledef-font-feature-values">@font-feature-values</dfn></p>
<pre class="prod">
<dfn data-dfn-for="@font-feature-values" data-dfn-type="at-rule" data-export="" id="at-ruledef-font-feature-values-stylistic">@stylistic</dfn> = @stylistic { &lt;declaration-list&gt; }
</pre>
`,
propertyName: "atrules",
css: [{
name: "@font-feature-values",
prose: "@font-feature-values",
value: "<family-name># { <declaration-rule-list> }",
descriptors: [
{
for: "@font-feature-values",
name: "@stylistic",
type: "at-rule",
value: "@stylistic { <declaration-list> }"
}
]
}]
},


{
title: "ignores definitions that describe changes",
html: `<table class="propdef">
Expand Down