Skip to content

Commit 38ed41a

Browse files
authored
Adjust index() in CSS package to also index descriptors (#1624)
The consolidated CSS file is mostly flat except for descriptors that are nested under at-rules. The descriptors were still using an array. For consistency, the `index()` function now indexes them by name too. README was also updated to drop the note on at-rules syntax expansion since we no longer do that. It also notes that the list of descriptors is not guaranteed to be exhaustive.
1 parent 71eb284 commit 38ed41a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

packages/css/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const ast = definitionSyntax.parse(properties['flex'].syntax);
5050

5151
Additional keys may be set depending on the type of the CSS feature. For example:
5252

53-
- At-rules have a `descriptors` key that contains the list of descriptors defined for the given at-rule.
53+
- At-rules have a `descriptors` key that contains the list of descriptors defined for the given at-rule. That list may not be exhaustive. For example, it does not contain descriptors that are only implicitly defined in specs, such as families of properties that some at-rules (e.g, `@position-try`) accept as descriptors.
5454
- Functions and types that are scoped to a property or other feature have a `for` key that contains the list of scoping features for that feature. A scoping feature may be a property, a function or a type. When the scoping feature is a type, its name in the `for` key is enclosed between `<` and `>`.
5555
- Properties have a `styleDeclaration` key that contains the list of IDL attribute names that the property generates. A number of other keys may be set to describe the property's initial value, animation type and other parameters.
5656

@@ -59,7 +59,6 @@ Additional notes:
5959
- When a feature is defined across different levels in the same spec series, the definition from the latest level is used.
6060
- When a property is extended with new values in different specs, `href` links to the base definition and `syntax` is the union (using `|`) of the syntaxes of the base and extended definitions.
6161
- When new descriptors are defined for an at-rule in different specs, `descriptors` contains the merged list of known descriptors.
62-
- When specs define the syntax of an at-rule in terms of `<declaration-list>` or `<declaration-rule-list>`, the `syntax` key contains an "expanded" syntax that leverages the syntax of the at-rule's descriptors.
6362

6463
## Migrating from `mdn/data`
6564

packages/css/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ async function index({folder = __dirname} = {}) {
2424
id += ' for ' + feature.for[0];
2525
}
2626
indexed[category][id] = feature;
27+
28+
// For at-rules, convert descriptors array into an indexed object too
29+
if (feature.descriptors) {
30+
const descriptors = feature.descriptors;
31+
feature.descriptors = {};
32+
for (const descriptor of descriptors) {
33+
feature.descriptors[descriptor.name] = descriptor;
34+
}
35+
}
2736
}
2837
}
2938
return indexed;

test/css/consolidated.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ describe(`The consolidated CSS file`, async () => {
7979
`Not the right amount of ${pluralize(label)} in index`);
8080
}
8181

82-
assert(indexed.atrules['@import'], `No flex property in index`);
82+
for (const [name, atrule] of Object.entries(indexed.atrules)) {
83+
const initial = consolidated.atrules.find(a => a.name === name);
84+
assert(initial, `No ${name} at-rule in index`);
85+
assert.equal(
86+
Object.keys(atrule.descriptors).length,
87+
initial.descriptors.length,
88+
`Not the right amount of descriptors for ${name} in index`);
89+
}
90+
91+
assert(indexed.atrules['@import'], `No @import at-rule in index`);
8392
assert(indexed.functions['abs()'], `No abs() function in index`);
8493
assert(indexed.properties['flex'], `No flex property in index`);
8594
assert(indexed.selectors[':first-child'], `No :first-child selector in index`);

0 commit comments

Comments
 (0)