Skip to content

Commit

Permalink
feat: Add an error for the deprecated @value at-rule of CSS Modules (
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Nov 3, 2024
1 parent ddc9ce8 commit 41a07a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub enum ParserError<'i> {
InvalidNesting,
/// The @nest rule is deprecated.
DeprecatedNestRule,
/// The @value rule (of CSS modules) is deprecated.
DeprecatedCssModulesValueRule,
/// An invalid selector in an `@page` rule.
InvalidPageSelector,
/// An invalid value was encountered.
Expand Down Expand Up @@ -118,6 +120,7 @@ impl<'i> fmt::Display for ParserError<'i> {
InvalidMediaQuery => write!(f, "Invalid media query"),
InvalidNesting => write!(f, "Invalid nesting"),
DeprecatedNestRule => write!(f, "The @nest rule is deprecated"),
DeprecatedCssModulesValueRule => write!(f, "The @value rule is deprecated"),
InvalidPageSelector => write!(f, "Invalid page selector"),
InvalidValue => write!(f, "Invalid value"),
QualifiedRuleInvalid => write!(f, "Invalid qualified rule"),
Expand Down
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,20 @@ mod tests {
}
}

fn css_modules_error_test(source: &str, error: ParserError) {
let res = StyleSheet::parse(
&source,
ParserOptions {
css_modules: Some(Default::default()),
..Default::default()
},
);
match res {
Ok(_) => unreachable!(),
Err(e) => assert_eq!(e.kind, error),
}
}

macro_rules! map(
{ $($key:expr => $name:literal $(referenced: $referenced: literal)? $($value:literal $(global: $global: literal)? $(from $from:literal)?)*),* } => {
{
Expand Down Expand Up @@ -27691,6 +27705,14 @@ mod tests {
);
}

#[test]
fn test_css_modules_value_rule() {
css_modules_error_test(
"@value compact: (max-width: 37.4375em);",
ParserError::DeprecatedCssModulesValueRule,
);
}

#[test]
fn test_unknown_at_rules() {
minify_test("@foo;", "@foo;");
Expand Down
6 changes: 6 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,12 @@ impl<'a, 'o, 'b, 'i, T: crate::traits::AtRuleParser<'i>> AtRuleParser<'i> for Ne
let selectors = SelectorList::parse(&selector_parser, input, ParseErrorRecovery::DiscardList, NestingRequirement::Contained)?;
AtRulePrelude::Nest(selectors)
},

"value" if self.options.css_modules.is_some() => {
return Err(input.new_custom_error(ParserError::DeprecatedCssModulesValueRule));
},


_ => parse_custom_at_rule_prelude(&name, input, self.options, self.at_rule_parser)?
};

Expand Down

0 comments on commit 41a07a1

Please sign in to comment.