feat(css/parser): Implement error reporting for @value of CSS Modules (#8547)

This commit is contained in:
Donny/강동윤 2024-01-24 14:06:20 +09:00 committed by GitHub
parent c3fd9d081e
commit 00619b1708
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 492 additions and 0 deletions

View File

@ -72,6 +72,7 @@ impl Error {
format!("{} is not valid name for keyframes", s).into()
}
ErrorKind::InvalidScopeAtRule => "Invalid @scope at-rule".into(),
ErrorKind::ValueAtRule => "@value at-rule is deprecated".into(),
}
}
@ -119,4 +120,6 @@ pub enum ErrorKind {
InvalidScopeAtRule,
UnknownAtRuleNotTerminated,
ValueAtRule,
}

View File

@ -419,6 +419,19 @@ where
Some(prelude)
}
"value" => {
if self.config.css_modules {
let span = self.input.cur_span();
let _: ComponentValue = self.parse()?;
self.errors.push(Error::new(span, ErrorKind::ValueAtRule));
self.input.skip_ws();
}
return Err(Error::new(Default::default(), ErrorKind::Ignore));
}
_ => {
return Err(Error::new(Default::default(), ErrorKind::Ignore));
}

View File

@ -628,6 +628,24 @@ fn recovery(input: PathBuf) {
stylesheet_recovery_test_tokens(input, Default::default());
}
#[testing::fixture("tests/recovery-cssmodules/**/input.css")]
fn recovery_2(input: PathBuf) {
stylesheet_recovery_test(
input.clone(),
ParserConfig {
css_modules: true,
..Default::default()
},
);
stylesheet_recovery_test_tokens(
input,
ParserConfig {
css_modules: true,
..Default::default()
},
);
}
#[testing::fixture("tests/fixture/**/input.css")]
#[testing::fixture("tests/recovery/**/input.css")]
fn span_visualizer(input: PathBuf) {

View File

@ -0,0 +1,8 @@
@value blue: #0c77f8;
@value red: #ff0000;
@value green: #aaf200;
.button {
color: blue;
display: inline-block;
}

View File

@ -0,0 +1,428 @@
{
"type": "Stylesheet",
"span": {
"start": 1,
"end": 119,
"ctxt": 0
},
"rules": [
{
"type": "AtRule",
"span": {
"start": 1,
"end": 22,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 2,
"end": 7,
"ctxt": 0
},
"value": "value",
"raw": "value"
},
"prelude": {
"type": "ListOfComponentValues",
"span": {
"start": 7,
"end": 21,
"ctxt": 0
},
"children": [
{
"type": "PreservedToken",
"span": {
"start": 7,
"end": 8,
"ctxt": 0
},
"token": {
"WhiteSpace": {
"value": " "
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 8,
"end": 12,
"ctxt": 0
},
"token": {
"Ident": {
"value": "blue",
"raw": "blue"
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 12,
"end": 13,
"ctxt": 0
},
"token": "Colon"
},
{
"type": "PreservedToken",
"span": {
"start": 13,
"end": 14,
"ctxt": 0
},
"token": {
"WhiteSpace": {
"value": " "
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 14,
"end": 21,
"ctxt": 0
},
"token": {
"Hash": {
"is_id": false,
"value": "0c77f8",
"raw": "0c77f8"
}
}
}
]
},
"block": null
},
{
"type": "AtRule",
"span": {
"start": 23,
"end": 43,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 24,
"end": 29,
"ctxt": 0
},
"value": "value",
"raw": "value"
},
"prelude": {
"type": "ListOfComponentValues",
"span": {
"start": 29,
"end": 42,
"ctxt": 0
},
"children": [
{
"type": "PreservedToken",
"span": {
"start": 29,
"end": 30,
"ctxt": 0
},
"token": {
"WhiteSpace": {
"value": " "
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 30,
"end": 33,
"ctxt": 0
},
"token": {
"Ident": {
"value": "red",
"raw": "red"
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 33,
"end": 34,
"ctxt": 0
},
"token": "Colon"
},
{
"type": "PreservedToken",
"span": {
"start": 34,
"end": 35,
"ctxt": 0
},
"token": {
"WhiteSpace": {
"value": " "
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 35,
"end": 42,
"ctxt": 0
},
"token": {
"Hash": {
"is_id": true,
"value": "ff0000",
"raw": "ff0000"
}
}
}
]
},
"block": null
},
{
"type": "AtRule",
"span": {
"start": 44,
"end": 66,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 45,
"end": 50,
"ctxt": 0
},
"value": "value",
"raw": "value"
},
"prelude": {
"type": "ListOfComponentValues",
"span": {
"start": 50,
"end": 65,
"ctxt": 0
},
"children": [
{
"type": "PreservedToken",
"span": {
"start": 50,
"end": 51,
"ctxt": 0
},
"token": {
"WhiteSpace": {
"value": " "
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 51,
"end": 56,
"ctxt": 0
},
"token": {
"Ident": {
"value": "green",
"raw": "green"
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 56,
"end": 57,
"ctxt": 0
},
"token": "Colon"
},
{
"type": "PreservedToken",
"span": {
"start": 57,
"end": 58,
"ctxt": 0
},
"token": {
"WhiteSpace": {
"value": " "
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 58,
"end": 65,
"ctxt": 0
},
"token": {
"Hash": {
"is_id": true,
"value": "aaf200",
"raw": "aaf200"
}
}
}
]
},
"block": null
},
{
"type": "QualifiedRule",
"span": {
"start": 68,
"end": 119,
"ctxt": 0
},
"prelude": {
"type": "SelectorList",
"span": {
"start": 68,
"end": 75,
"ctxt": 0
},
"children": [
{
"type": "ComplexSelector",
"span": {
"start": 68,
"end": 75,
"ctxt": 0
},
"children": [
{
"type": "CompoundSelector",
"span": {
"start": 68,
"end": 75,
"ctxt": 0
},
"nestingSelector": null,
"typeSelector": null,
"subclassSelectors": [
{
"type": "ClassSelector",
"span": {
"start": 68,
"end": 75,
"ctxt": 0
},
"text": {
"type": "Ident",
"span": {
"start": 69,
"end": 75,
"ctxt": 0
},
"value": "button",
"raw": "button"
}
}
]
}
]
}
]
},
"block": {
"type": "SimpleBlock",
"span": {
"start": 76,
"end": 119,
"ctxt": 0
},
"name": {
"type": "PreservedToken",
"span": {
"start": 76,
"end": 77,
"ctxt": 0
},
"token": "LBrace"
},
"value": [
{
"type": "Declaration",
"span": {
"start": 80,
"end": 91,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 80,
"end": 85,
"ctxt": 0
},
"value": "color",
"raw": "color"
},
"value": [
{
"type": "Ident",
"span": {
"start": 87,
"end": 91,
"ctxt": 0
},
"value": "blue",
"raw": "blue"
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 95,
"end": 116,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 95,
"end": 102,
"ctxt": 0
},
"value": "display",
"raw": "display"
},
"value": [
{
"type": "Ident",
"span": {
"start": 104,
"end": 116,
"ctxt": 0
},
"value": "inline-block",
"raw": "inline-block"
}
],
"important": null
}
]
}
}
]
}

View File

@ -0,0 +1,22 @@
x @value at-rule is deprecated
,-[$DIR/tests/recovery-cssmodules/value/input.css:1:1]
1 | @value blue: #0c77f8;
: ^
2 | @value red: #ff0000;
`----
x @value at-rule is deprecated
,-[$DIR/tests/recovery-cssmodules/value/input.css:1:1]
1 | @value blue: #0c77f8;
2 | @value red: #ff0000;
: ^
3 | @value green: #aaf200;
`----
x @value at-rule is deprecated
,-[$DIR/tests/recovery-cssmodules/value/input.css:2:1]
2 | @value red: #ff0000;
3 | @value green: #aaf200;
: ^
`----