Skip to content

Commit

Permalink
fix(css-syntax): explicitly order specs (#11101)
Browse files Browse the repository at this point in the history
* fix(css-syntax): explicitly order specs

Right now we rely on somewhat predictable ordering from readdir in
webref/css. Let's make this explicit for now.

* lint
  • Loading branch information
fiji-flo authored May 15, 2024
1 parent 6025c0e commit 8e8cd78
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions kumascript/src/lib/css-syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,21 +560,38 @@ export async function getCSSSyntax(
let parsedWebRefCache: null | Promise<WebRefObjectData> = null;
async function getParsedWebRef(): Promise<WebRefObjectData> {
if (!parsedWebRefCache) {
parsedWebRefCache = getRawWebRefData().then((rawItems) =>
Object.fromEntries(
Object.entries(rawItems).map(
([name, { spec, properties, atrules, values }]) => [
name,
{
spec,
properties: byName(properties),
atrules: byName(atrules),
values: byName(values),
},
]
)
)
);
parsedWebRefCache = getRawWebRefData().then((rawItems) => {
const sortedRawItems = [...Object.entries(rawItems)];
sortedRawItems.sort(([a], [b]) => {
if (a === b) {
return 0;
}
if (/-\d+$/.test(a) && a.replace(/-\d+$/, "") === b) {
return -1;
}
if (/-\d+$/.test(b) && b.replace(/-\d+$/, "") === a) {
return 1;
}
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
return Object.fromEntries(
sortedRawItems.map(([name, { spec, properties, atrules, values }]) => [
name,
{
spec,
properties: byName(properties),
atrules: byName(atrules),
values: byName(values),
},
])
);
});
}

return parsedWebRefCache;
Expand Down

0 comments on commit 8e8cd78

Please sign in to comment.