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

Extract CSS at-rules, move descriptors under at-rules #1033

Merged
merged 1 commit into from
Aug 17, 2022
Merged

Conversation

tidoust
Copy link
Member

@tidoust tidoust commented Jul 29, 2022

This creates an atrules property in CSS extracts that contains at-rules syntax as suggested in #1028. Descriptors associated with an at-rule (and all selectors are associated with an at-rule in practice) now appear under the at-rule definition.

The new atrules property contains a value property when a formal syntax could be extracted from the spec, and a descriptors array that lists descriptors associated with the at-rule (if any).

Breaking change: The former descriptors property that appeared at the root level of the extract no longer exists. The same info can be found under the atrules property.

This update also adjusts a couple of tests and adds two new tests on at-rules extraction.

The code can only extract the formal syntax of an at-rule if it is defined in a <pre class="prod"> block. That is the case in most CSS specs, but some of the definitions are done in <pre> tags without any class for now (e.g. @counter-style and @scroll-timeline). The specs need fixing or the extraction logic needs to also parse mere <pre> tags (but that seems fragile).

As opposed to the structure proposed in #1028, the list of descriptors is not indexed by the descriptor's name.

For instance, the @container at-rule would lead to:

{
  "@container": {
    "value": "@container [ <container-name> ]? <container-condition> { <stylesheet> }",
    "descriptors": [
      {
        "name": "width",
        "for": "@container",
        "value": "<length>",
        "type": "range"
      },
      {
        "name": "height",
        "for": "@container",
        "value": "<length>",
        "type": "range"
      },
      {
        "name": "inline-size",
        "for": "@container",
        "value": "<length>",
        "type": "range"
      },
      {
        "name": "block-size",
        "for": "@container",
        "value": "<length>",
        "type": "range"
      },
      {
        "name": "aspect-ratio",
        "for": "@container",
        "value": "<ratio>",
        "type": "range"
      },
      {
        "name": "orientation",
        "for": "@container",
        "value": "portrait | landscape",
        "type": "discrete"
      }
    ]
  }
}

Creating the pull request as draft as I still need to run additional tests to make sure that the code successfully extracts all known at-rules defined in CSS specs (or that the specs need fixing).

This creates an `atrules` property in CSS extracts that contains at-rules
syntax as suggested in #1028. Descriptors associated with an at-rule (and all
selectors are associated with an at-rule in practice) now appear under the
at-rule definition.

The new `atrules` property contains a `value` property when a formal syntax
could be extracted from the spec, and a `descriptors` array that lists
descriptors associated with the at-rule (if any).

Breaking change: The former `descriptors` property that appeared at the root
level of the extract no longer exists. The same info can be found under the
`atrules` property.

This update also adjusts a couple of tests and adds two new tests on at-rules
extraction.

The code can only extract the formal syntax of an at-rule if it is defined in
a `<pre class="prod">` block. That is the case in most CSS specs, but some of
the definitions are done in `<pre>` tags without any class for now (e.g.
`@counter-style` and `@scroll-timeline`). The specs need fixing or the
extraction logic needs to also parse mere `<pre>` tags (but that seems fragile).

As opposed to the structure proposed in #1028, the list of descriptors is not
indexed by the descriptor's name.

For instance, the `@container` at-rule would lead to:

```json
{
  "@container": {
    "value": "@container [ <container-name> ]? <container-condition> { <stylesheet> }",
    "descriptors": [
      {
        "name": "width",
        "for": "@container",
        "value": "<length>",
        "type": "range"
      },
      {
        "name": "height",
        "for": "@container",
        "value": "<length>",
        "type": "range"
      },
      {
        "name": "inline-size",
        "for": "@container",
        "value": "<length>",
        "type": "range"
      },
      {
        "name": "block-size",
        "for": "@container",
        "value": "<length>",
        "type": "range"
      },
      {
        "name": "aspect-ratio",
        "for": "@container",
        "value": "<ratio>",
        "type": "range"
      },
      {
        "name": "orientation",
        "for": "@container",
        "value": "portrait | landscape",
        "type": "discrete"
      }
    ]
  }
}
```
@tidoust tidoust marked this pull request as ready for review August 16, 2022 20:07
@tidoust tidoust requested a review from dontcallmedom August 16, 2022 20:08
@tidoust
Copy link
Member Author

tidoust commented Aug 16, 2022

Marking the PR as ready for review as tests confirm that the code correctly extracts anything that can be extracted (see #1028 (comment)).

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.

I didn't expect this would land so fast, amazing!

@tidoust tidoust merged commit e24c77e into main Aug 17, 2022
@tidoust tidoust deleted the css-atrules branch August 17, 2022 07:42
tidoust added a commit that referenced this pull request Aug 17, 2022
Breaking change:
- Extract CSS at-rules, move descriptors under at-rules (#1033)

Dependencies bumped:
- Bump web-specs from 2.18.0 to 2.19.0 (#1041)
- Bump puppeteer from 15.5.0 to 16.1.1 (#1040)
- Bump rollup from 2.77.2 to 2.78.0 (#1039)
- Bump respec from 32.2.1 to 32.2.3 (#1038)

How to upgrade:
The breaking change only affects code that makes use of the `descriptors`
property in CSS extracts. That property no longer exists in v9.0.0. Descriptors
are now grouped per at-rule in CSS extracts, available under the new
`atrules` property.
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