From 4572ca41566187e908c8c7e23950dcd6561145e1 Mon Sep 17 00:00:00 2001 From: zakybilfagih Date: Tue, 24 Dec 2024 19:52:47 +0700 Subject: [PATCH 1/2] fix: ampersand not resolved correctly on global --- packages/runtime/native/CSS.ml | 6 +----- packages/runtime/test/test_styles.ml | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/runtime/native/CSS.ml b/packages/runtime/native/CSS.ml index e2d003a55..3866a8138 100644 --- a/packages/runtime/native/CSS.ml +++ b/packages/runtime/native/CSS.ml @@ -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 diff --git a/packages/runtime/test/test_styles.ml b/packages/runtime/test/test_styles.ml index a753b3091..2aade3a55 100644 --- a/packages/runtime/test/test_styles.ml +++ b/packages/runtime/test/test_styles.ml @@ -1045,10 +1045,11 @@ let global_with_selector = [%global {| html { line-height: 1.15; } a { :hover { padding: 0; } } + .foo { & .bar & .baz { padding: 0; } } |}]; let css = get_string_style_rules () in assert_string css - (Printf.sprintf "html{line-height:1.15;}a{}a:hover{padding:0;}") + (Printf.sprintf "html{line-height:1.15;}a{}a:hover{padding:0;}.foo{}.foo .bar .foo .baz{padding:0;}") let tests = ( "CSS", From f25cd80f7a0d12dad59b07598a3904e8912344c2 Mon Sep 17 00:00:00 2001 From: zakybilfagih Date: Tue, 24 Dec 2024 22:39:14 +0700 Subject: [PATCH 2/2] chore: create new test for ampersand global --- packages/runtime/test/test_styles.ml | 32 ++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/runtime/test/test_styles.ml b/packages/runtime/test/test_styles.ml index 2aade3a55..d6a61a220 100644 --- a/packages/runtime/test/test_styles.ml +++ b/packages/runtime/test/test_styles.ml @@ -1045,11 +1045,38 @@ let global_with_selector = [%global {| html { line-height: 1.15; } a { :hover { padding: 0; } } - .foo { & .bar & .baz { padding: 0; } } |}]; let css = get_string_style_rules () in assert_string css - (Printf.sprintf "html{line-height:1.15;}a{}a:hover{padding:0;}.foo{}.foo .bar .foo .baz{padding:0;}") + (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", @@ -1108,4 +1135,5 @@ let tests = mq_inside_selector_with_declarations; mq_and_selectors_2; global_with_selector; + ampersand_everywhere_global; ] )