question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support <general-enclosed> in @supports

See original GitHub issue

Added by @nex3


Hi @nex3 and friends! I’ve noticed that there are a few gaps between CSS’s specified syntax and what dart-sass will parse, one area in particular is parsing @supports conditions. The following examples should all be valid in CSS syntax but each generate parsing errors in dart-sass:

@supports (a b) {}
@supports c(d) {}
@supports (e(f)) {}

The syntax for @supports conditions in CSS is defined here: https://drafts.csswg.org/css-conditional-3/#typedef-supports-condition

<supports-condition> = not <supports-in-parens>
                     | <supports-in-parens> [ and <supports-in-parens> ]*
                     | <supports-in-parens> [ or <supports-in-parens> ]*
<supports-in-parens> = ( <supports-condition> ) | <supports-feature> | <general-enclosed>
<supports-feature> = <supports-decl>
<supports-decl> = ( <declaration> )

One thing that seems missing is that the CSS syntax allows <general-enclosed> productions, which are very open-ended in what they can contain.

<general-enclosed> = [ <function-token> <any-value> ) ] | ( <ident> <any-value> )

It looks like this might be the section of the dart-sass parser where these conditions are read, but I’m not sure right now how to fix this or improve the code that’s there.

When tokenized as CSS, @supports c(d) {} should look like this:

{
  "type": "AT-RULE",
  "value": {
    "type": "BLOCK",
    "value": [],
    "name": "{"
  },
  "name": "supports",
  "prelude": [
    {
      "token": "WHITESPACE"
    },
    {
      "type": "FUNCTION",
      "value": [
        {
          "token": "IDENT",
          "value": "d"
        }
      ],
      "name": "c"
    },
    {
      "token": "WHITESPACE"
    }
  ]
}

You can use this tool to check what different browsers will parse out of a string of CSS input. Or run this code to parse and re-stringify a string of CSS in any browser to see the same kind of result:

import('https://unpkg.com/cssomtools').then(({parse, stringify}) =>
  console.log(
    stringify(
      parse`
         @supports c(d) {}
      `
    )
  )
)

It looks like Safari struggles with @supports conditions that aren’t inside () parens, but Chrome and Firefox both seem to follow the spec a little more closely:

Safari

safari-mostly-works

Firefox

firerox-all-work

It would be great if dart-sass could parse CSS more accurately in this area, please let me know if there’s any way I can be of further help in identifying or testing this.

Thanks ❤️

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
nex3commented, Mar 9, 2020

Marking this as accepted now.

1reaction
nex3commented, Nov 27, 2019

I’m not making any claims about authorial intent, just the text of the specification, which is unambiguous. Regardless, this is all irrelevant to Sass since we plan on adding support for <general-enclosed> whether or not your use case is valid CSS, so I would like to stop discussing it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

supports - CSS: Cascading Style Sheets - MDN Web Docs
The @supports CSS at-rule lets you specify CSS declarations that depend on a browser's support for CSS features. Using this at-rule is ...
Read more >
@supports - CSS - W3cubDocs
The @supports CSS at-rule lets you specify declarations that depend on a browser's support for one or more specific CSS features. This is...
Read more >
[mediaqueries] Excluding '!' and ';' in <general-enclosed>?
This is so that '@support (--a: b; c) {}' doesn't parse as a custom ... Note that the @supports grammar has a similar...
Read more >
@supports [ CSS ] - KruXoR
The @supports CSS at-rule lets you specify declarations that depend on a browser's support for one or more specific CSS features. This is...
Read more >
Fix support for @supports WPT tests 40, 41, and 42 [chromium ...
a) Allow empty parentheses in a supports statement (test cases 40, 41) b) Correctly use <general-enclosed> when a false-positive nested condition
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found