microsoft / vscode-css-languageservice

CSS, LESS & SCSS language service extracted from VSCode to be reused, e.g in the Monaco editor.
MIT License
309 stars 175 forks source link

Parse CSS modules syntax for @keyframes :local(ident) #393

Open jsnajdr opened 1 month ago

jsnajdr commented 1 month ago

The VSCode CSS parser fails to parse the CSS modules syntax for scoping keyframes identifiers:

Screenshot 2024-05-24 at 13 22 36

The SASS tool (both the Dart and C++) implementations parse the @keyframes identifier either as a selector, or just as a generic raw params string (anything between atrule and start of the block), I'm not sure. But they are able to pass the :local(ident) string to a tool like postcss-modules which transforms it into a valid, locally scoped identifier.

mirka commented 1 month ago

Might be obvious given the error ("identifier expected" rather than "unknown pseudo class" or something), but I'll add that this also isn't resolved by adding the pseudos to css.customData, e.g.:

{
    "version": 1.1,
    "pseudoClasses": [
        {
            "name": ":local",
            "description": "css modules local"
        }
    ]
}
jsnajdr commented 1 month ago

Pseudoclasses are used only when scoping selectors. This is CSS modules syntax that is already syntactically valid:

:local {
  .foo {
    color: blue;
  }
}

But @keyframes :local(foo) is a special incompatible extension. According to the standard, it should be only a simple string identifier. And the VSCode CSS parser really insists that it's an identifier.