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

feat: Add an error for the deprecated @value at-rule of CSS Modules #842

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -27613,6 +27627,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
Loading