Skip to content

Commit

Permalink
fix: Fix codegen of :is(input:checked) (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Aug 1, 2024
1 parent 39964f1 commit f7c8831
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,8 +1624,13 @@ where

#[inline]
fn has_type_selector(selector: &Selector) -> bool {
let mut iter = selector.iter_raw_parse_order_from(0);
// For input:checked the component vector is
// [input, :checked] so we have to check it using matching order.
//
// This both happens for input:checked and is(input:checked)
let mut iter = selector.iter_raw_match_order();
let first = iter.next();

if is_namespace(first) {
is_type_selector(iter.next())
} else {
Expand Down
20 changes: 20 additions & 0 deletions tests/cli_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,3 +759,23 @@ fn browserslist_environment_from_browserslist_env() -> Result<(), Box<dyn std::e

Ok(())
}

#[test]
fn next_66191() -> Result<(), Box<dyn std::error::Error>> {
let infile = assert_fs::NamedTempFile::new("test.css")?;
infile.write_str(
r#"
.cb:is(input:checked) {
margin: 3rem;
}
"#,
)?;
let outfile = assert_fs::NamedTempFile::new("test.out")?;
let mut cmd = Command::cargo_bin("lightningcss")?;
cmd.arg(infile.path());
cmd.arg("--output-file").arg(outfile.path());
cmd.assert().success();
outfile.assert(predicate::str::contains(indoc! {r#".cb:is(input:checked)"#}));

Ok(())
}

0 comments on commit f7c8831

Please sign in to comment.