Skip to content

Commit

Permalink
feat(css/parser): Implement error reporting for @value of CSS Modul…
Browse files Browse the repository at this point in the history
…es (#8547)
  • Loading branch information
kdy1 authored Jan 24, 2024
1 parent c3fd9d0 commit 00619b1
Show file tree
Hide file tree
Showing 6 changed files with 492 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/swc_css_parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -119,4 +120,6 @@ pub enum ErrorKind {
InvalidScopeAtRule,

UnknownAtRuleNotTerminated,

ValueAtRule,
}
13 changes: 13 additions & 0 deletions crates/swc_css_parser/src/parser/at_rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
18 changes: 18 additions & 0 deletions crates/swc_css_parser/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@value blue: #0c77f8;
@value red: #ff0000;
@value green: #aaf200;

.button {
color: blue;
display: inline-block;
}
Loading

0 comments on commit 00619b1

Please sign in to comment.