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

fix(css-syntax): explicitly order specs #11101

Merged
merged 2 commits into from
May 15, 2024
Merged

Conversation

fiji-flo
Copy link
Contributor

@fiji-flo fiji-flo commented May 9, 2024

Summary

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

Problem

       The order in which filenames are read by successive calls to
       readdir() depends on the filesystem implementation; it is
       unlikely that the names will be sorted in any fashion.

Solution

Explicitly sort the spec names, preserving the current behavior.


How did you test this change?

No difference vs a build using main.

Right now we rely on somewhat predictable ordering from readdir in
webref/css. Let's make this explicit for now.
@fiji-flo fiji-flo requested a review from a team as a code owner May 9, 2024 15:22
@github-actions github-actions bot added the macros tracking issues related to kumascript macros label May 9, 2024
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but the sort function could be more concise:

Comment on lines 569 to 578
if (/-\d+$/.test(a)) {
if (a.replace(/-\d+$/, "") === b) {
return -1;
}
}
if (/-\d+$/.test(b)) {
if (b.replace(/-\d+$/, "") === a) {
return 1;
}
}
Copy link
Contributor

@caugner caugner May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (/-\d+$/.test(a)) {
if (a.replace(/-\d+$/, "") === b) {
return -1;
}
}
if (/-\d+$/.test(b)) {
if (b.replace(/-\d+$/, "") === a) {
return 1;
}
}
const suffix = /-\d+$/;
if (suffix.test(a) && (a.replace(suffix, "") === b)) {
return -1;
}
if (suffix.test(b) && (b.replace(suffix, "") === a)) {
return 1;
}

Comment on lines +579 to +585
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
return a.localeCompare(b);

Copy link
Contributor Author

@fiji-flo fiji-flo May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

["css-foo", "CSS-bar", "css-2000"].toSorted((a,b) => a.localeCompare(b))
[ "css-2000", "CSS-bar", "css-foo" ]

["css-foo", "CSS-bar", "css-2000"].toSorted((a,b) => a == b ? 0 : a < b ? -1 : 1)
[ "CSS-bar", "css-2000", "css-foo" ]

We want case sensitive sorting here.

@fiji-flo fiji-flo merged commit 8e8cd78 into main May 15, 2024
14 checks passed
@fiji-flo fiji-flo deleted the enhance-css-formal-syntax-part-3 branch May 15, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macros tracking issues related to kumascript macros
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants