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

CSS extracts: handle function dfns on right hand side of production rules #1129

Merged
merged 2 commits into from
Nov 30, 2022

Conversation

tidoust
Copy link
Member

@tidoust tidoust commented Nov 30, 2022

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:

{
  "name": "linear()",
  "type": "function"
}

This update fixes that, meaning the final extract will now contain:

{
  "name": "linear()",
  "type": "function",
  "value": "linear(<linear-stop-list>)"
}

…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>)"
}
```
Copy link
Member

@dontcallmedom dontcallmedom left a 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

// 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_\-]+\([^\)]+\)$/)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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) {

// 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];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member Author

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.

@tidoust tidoust merged commit bd227e8 into main Nov 30, 2022
@tidoust tidoust deleted the css-rhs branch November 30, 2022 11:57
tidoust added a commit that referenced this pull request Nov 30, 2022
Bugs fixed:
- CSS: handle function dfns on right hand side of production rules (#1129)
- CSS: handle dfns with multiple linking texts (#1128)
- Dfns: Relax duplicate filtering rules to only look at exported dfns (#1126)

Dependencies bumped:
- Bump respec from 32.3.0 to 32.4.0 (#1127)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants