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] fix parsing of custom properties in @supports #82178

Closed
JaneOri opened this issue Oct 9, 2019 · 9 comments · Fixed by gizlang/gizcode-extension-samples#95 · 4 remaining pull requests
Closed

[css] fix parsing of custom properties in @supports #82178

JaneOri opened this issue Oct 9, 2019 · 9 comments · Fixed by gizlang/gizcode-extension-samples#95 · 4 remaining pull requests
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug css-less-scss Issues and items concerning CSS,Less,SCSS styling verified Verification succeeded
Milestone

Comments

@JaneOri
Copy link

JaneOri commented Oct 9, 2019

  • VSCode Version: 1.39.0
  • OS Version: Windows 10

Steps to Reproduce:

  1. Create a CSS file with this code:
.test {
    --validValue: , 0 0;
}
@supports not (--validValue: , 0 0) {
  .vscode-parsing-error {
      content: "";
  }
}
  1. You'll get these errors:
    image

Does this issue occur when all extensions are disabled?: Yes, no extensions installed

@vscodebot
Copy link

vscodebot bot commented Oct 9, 2019

@vscodebot vscodebot bot added the new release label Oct 9, 2019
@aeschli aeschli added the css-less-scss Issues and items concerning CSS,Less,SCSS styling label Oct 10, 2019
@aeschli aeschli added this to the Backlog milestone Oct 10, 2019
@aeschli aeschli added the bug Issue identified by VS Code Team member as probable bug label Oct 10, 2019
@aeschli aeschli changed the title CSS Validation/Linting error [css] issue with coma separated values Oct 10, 2019
@aeschli
Copy link
Contributor

aeschli commented Feb 21, 2020

Are you sure that starting with a comma is valid CSS?

https://www.sassmeister.com/ also shows an error on the comma ( I know that SASS, but also understands CSS).

@aeschli aeschli closed this as completed Feb 21, 2020
@JaneOri
Copy link
Author

JaneOri commented Feb 21, 2020

Hello @aechan

Yes, I am certain.

Earlier versions of Safari on iOS erroneously counted it as invalid too, but that has since been fixed. You can feature detect that fix with this CSS I provided:

@supports not (--validValue: , 0 0) {
  .vscode-parsing-error {
      content: "";
  }
}

Here are some resources on the validity of the value

I've quoted the relevant pieces in a human-readable order for your convenience:

https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties#Validity_and_values

The classical CSS concept of validity, tied to each property, is not very useful in regard to custom properties. When the values of the custom properties are parsed, the browser doesn't know where they will be used, so must, therefore, consider nearly all values as valid.

https://drafts.csswg.org/css-variables/#invalid-variables

variables can’t "fail early" like other syntax errors can

A declaration can be invalid at computed-value time if it contains a var() that references a custom property with the guaranteed-invalid value [...] or if it uses a valid custom property, but the property value, after substituting its var() functions, is invalid.

https://drafts.csswg.org/css-variables/#guaranteed-invalid

The initial value of a custom property is a guaranteed-invalid value.

This value serializes as the empty string, but actually writing an empty value into a custom property, like --foo: ;, is a valid (empty) value, not the guaranteed-invalid value. If, for whatever reason, one wants to manually reset a variable to the guaranteed-invalid value, using the keyword initial will do this.

https://developer.mozilla.org/en-US/docs/Web/CSS/--*#Syntax

Formal Syntax <declaration-value>

https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value

The <declaration-value> production matches any sequence of one or more tokens, so long as the sequence does not contain <bad-string-token>, <bad-url-token>, unmatched <)-token>, <]-token>, or <}-token>, or top-level <semicolon-token> tokens or <delim-token> tokens with a value of "!". It represents the entirety of what a valid declaration can have as its value.

<bad-string-token>, <bad-url-token>, and <delim-token> are variations of code points, typically beginning with "U+":
https://infra.spec.whatwg.org/#code-point


augmented-ui relies heavily on this to compose dynamic clip-path values if you would like a real world example:
https://github.com/propjockey/augmented-ui/blob/master/augmented.css#L251

Thank you,
//James

@JaneOri
Copy link
Author

JaneOri commented Feb 24, 2020

@octref @aeschli pinging in case the notification was lost over the weekend since the issue was closed early

thank you!

@aeschli
Copy link
Contributor

aeschli commented Feb 25, 2020

@James0x57 Thanks for the pointers!

@JaneOri
Copy link
Author

JaneOri commented Feb 28, 2020

@aeschli Could you please re-open this issue?

Values of a custom property should not be parsed for commas - commas have no meaning in this context.

Safari on iOS had the same issue and they've fixed it.

SASS also has this issue but they only handle it incorrectly in the @supports statements now.

The only work around is to disable the entire problem-checking feature in Visual Studio Code

@JaneOri
Copy link
Author

JaneOri commented Feb 28, 2020

Here is a minimal JSBin using this feature of CSS in case it's useful to you:
https://jsbin.com/cemujarozo/1/edit?html,css,output

The leading comma allows for dynamic, optional, composition of comma separated standard properties.

@aeschli aeschli reopened this Feb 28, 2020
@aeschli aeschli modified the milestones: Backlog, March 2020 Feb 28, 2020
@aeschli aeschli modified the milestones: March 2020, April 2020 Mar 30, 2020
@aeschli aeschli modified the milestones: April 2020, May 2020 Apr 27, 2020
@octref octref removed their assignment May 1, 2020
@aeschli aeschli modified the milestones: May 2020, June 2020 Jun 4, 2020
@aeschli aeschli modified the milestones: June 2020, July 2020 Jun 29, 2020
@JaneOri JaneOri changed the title [css] issue with coma separated values [css] Validation/Linting error: top-level commas in --css-variables: , should, be, ignored; Jul 14, 2020
@trusktr
Copy link

trusktr commented Jul 19, 2020

Great catch! The main thing is that CSS variables can be composed, so for example this is valid:

.foo {
  --a: anim;
  --b: 1s ,;
  --c: anim2 1s;
  --d: , anim3 2s;
  animation: var(--a) var(--b) var(--c) var(--d);
}

and now animation has the effective value anim 1s, anim2 1s, anim3 2s.

@aeschli aeschli modified the milestones: July 2020, On Deck Aug 2, 2020
@JaneOri
Copy link
Author

JaneOri commented Nov 14, 2020

Any chance of getting this back on the radar? In the last year since I filed this, VSCode has become my favorite editor but I still cannot use CSS Validation because of the false negative in the @supports statement:

image

Thank you for your consideration

@aeschli aeschli changed the title [css] Validation/Linting error: top-level commas in --css-variables: , should, be, ignored; [css] fix parsing of custom properties in @supports Nov 16, 2020
@aeschli aeschli modified the milestones: On Deck, November 2020 Nov 16, 2020
@sandy081 sandy081 added the verified Verification succeeded label Dec 3, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.