From f7c883131c3463756ac935496cfe5da710eec601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 2 Aug 2024 00:30:56 +0900 Subject: [PATCH] fix: Fix codegen of `:is(input:checked)` (#783) --- src/selector.rs | 7 ++++++- tests/cli_integration_tests.rs | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/selector.rs b/src/selector.rs index 62550198..56df04c8 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -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 { diff --git a/tests/cli_integration_tests.rs b/tests/cli_integration_tests.rs index 744ac7ca..c57d26e8 100644 --- a/tests/cli_integration_tests.rs +++ b/tests/cli_integration_tests.rs @@ -759,3 +759,23 @@ fn browserslist_environment_from_browserslist_env() -> Result<(), Box Result<(), Box> { + 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(()) +}