-
Notifications
You must be signed in to change notification settings - Fork 470
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
Conversation
Right now we rely on somewhat predictable ordering from readdir in webref/css. Let's make this explicit for now.
There was a problem hiding this 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:
kumascript/src/lib/css-syntax.ts
Outdated
if (/-\d+$/.test(a)) { | ||
if (a.replace(/-\d+$/, "") === b) { | ||
return -1; | ||
} | ||
} | ||
if (/-\d+$/.test(b)) { | ||
if (b.replace(/-\d+$/, "") === a) { | ||
return 1; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | |
} |
if (a < b) { | ||
return -1; | ||
} | ||
if (a > b) { | ||
return 1; | ||
} | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (a < b) { | |
return -1; | |
} | |
if (a > b) { | |
return 1; | |
} | |
return 0; | |
return a.localeCompare(b); |
There was a problem hiding this comment.
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.
Summary
Right now we rely on somewhat predictable ordering from readdir in webref/css. Let's make this explicit for now.
Problem
Solution
Explicitly sort the spec names, preserving the current behavior.
How did you test this change?
No difference vs a build using main.