Skip to content

Commit

Permalink
Ampersand not resolved correctly on global (#532)
Browse files Browse the repository at this point in the history
* fix: ampersand not resolved correctly on global

* chore: create new test for ampersand global
  • Loading branch information
zakybilfagih authored Dec 24, 2024
1 parent 6743ac9 commit 08feeab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/runtime/native/CSS.ml
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,7 @@ let resolve_selectors rules =
match prefix with
| None -> current_selector
| Some prefix ->
(* child starts with &, join them without space *)
if starts_with_ampersand current_selector then
prefix ^ remove_first_ampersand current_selector
(* child starts with dot, join them without space *)
else if contains_ampersand current_selector then
if contains_ampersand current_selector then
(* reemplazar el ampersand del current_selector, con el padre *)
replace_ampersand ~by:prefix current_selector
else if starts_with_double_dot current_selector then
Expand Down
29 changes: 29 additions & 0 deletions packages/runtime/test/test_styles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,34 @@ let global_with_selector =
assert_string css
(Printf.sprintf "html{line-height:1.15;}a{}a:hover{padding:0;}")

let ampersand_everywhere_global =
test "ampersand_everywhere_global" @@ fun () ->
[%global
{|
.foo {
&[data-foo=bar] .lola {
font-size: 2px;
}
& .lola &::placeholder {
font-size: 3px;
}
.lola &:not(a) {
font-size: 4px;
}
.lola {
font-size: 5px;
}
.lola & &:focus & & .lola {
font-size: 6px;
}
}
|}];
let css = get_string_style_rules () in
assert_string css
".foo{}.foo[data-foo=bar] .lola{font-size:2px;}.foo .lola .foo::placeholder{font-size:3px;}\
.lola .foo:not(a){font-size:4px;}.foo .lola{font-size:5px;}\
.lola .foo .foo:focus .foo .foo .lola{font-size:6px;}"

let tests =
( "CSS",
[
Expand Down Expand Up @@ -1107,4 +1135,5 @@ let tests =
mq_inside_selector_with_declarations;
mq_and_selectors_2;
global_with_selector;
ampersand_everywhere_global;
] )

0 comments on commit 08feeab

Please sign in to comment.