-
Notifications
You must be signed in to change notification settings - Fork 24
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 extracts: handle function dfns on right hand side of production rules #1129
Conversation
…ules Via w3c/webref#808 (comment) Once in a while, function definitions appear in the right hand side of a production rule, as in css-easing-2: ``` <linear-easing-function> = linear(<linear-stop-list>) ``` https://drafts.csswg.org/css-easing-2/#funcdef-linear The code did not extract the function parameters in such cases, leading to an reported object without a `value` property: ```json { "name": "linear()", "type": "function" } ``` This update fixes that, meaning the final extract will now contain: ```json { "name": "linear()", "type": "function", "value": "linear(<linear-stop-list>)" } ```
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 with a minor readability suggestion
src/browserlib/extract-cssdfn.mjs
Outdated
// side of a production rule, as in the definition of "linear()" in | ||
// css-easing-2: https://drafts.csswg.org/css-easing-2/#funcdef-linear | ||
// In such a case, we still want to extract the function parameters | ||
if (dfn.textContent.trim().match(/^[a-zA-Z_][a-zA-Z0-9_\-]+\([^\)]+\)$/)) { |
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 (dfn.textContent.trim().match(/^[a-zA-Z_][a-zA-Z0-9_\-]+\([^\)]+\)$/)) { | |
const matchFunctionDefinition = dfn.textContent.trim().match(/^[a-zA-Z_][a-zA-Z0-9_\-]+\([^\)]+\)$/); | |
if (matchFunctionDefinition) { |
src/browserlib/extract-cssdfn.mjs
Outdated
// css-easing-2: https://drafts.csswg.org/css-easing-2/#funcdef-linear | ||
// In such a case, we still want to extract the function parameters | ||
if (dfn.textContent.trim().match(/^[a-zA-Z_][a-zA-Z0-9_\-]+\([^\)]+\)$/)) { | ||
const fn = dfn.textContent.trim().match(/^([a-zA-Z_][a-zA-Z0-9_\-]+)\([^\)]+\)$/)[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.
const fn = dfn.textContent.trim().match(/^([a-zA-Z_][a-zA-Z0-9_\-]+)\([^\)]+\)$/)[1]; | |
const fn = matchFunctionDefinition[1]; |
regexp are painful enough to read, so I suggest DRYing them
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.
Done. FYI, the first and second regexps were different because the second one used a capturing group while the first one did not. The same logic also appeared elsewhere in the code.
Via w3c/webref#808 (comment)
Once in a while, function definitions appear in the right hand side of a production rule, as in css-easing-2:
https://drafts.csswg.org/css-easing-2/#funcdef-linear
The code did not extract the function parameters in such cases, leading to an reported object without a
value
property:This update fixes that, meaning the final extract will now contain: