From 15b2412e3432d704079d2fa4c2845db43c6541de Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 23 Apr 2020 15:41:13 +1200 Subject: [PATCH] Correct pseudoclass to pseudoelement rewrites to apply to only rightmost selector. I previously got the semantics of my datastructures backwards: the head is the rightmost selector. --- src/Data/CSS/Preprocessor/PsuedoClasses.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Data/CSS/Preprocessor/PsuedoClasses.hs b/src/Data/CSS/Preprocessor/PsuedoClasses.hs index c9d6dc8..a21a2fe 100644 --- a/src/Data/CSS/Preprocessor/PsuedoClasses.hs +++ b/src/Data/CSS/Preprocessor/PsuedoClasses.hs @@ -9,7 +9,7 @@ import Data.CSS.Syntax.Selector import Data.CSS.Syntax.Tokens import Data.Text as Txt -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe, listToMaybe) import Data.HashMap.Lazy as HM import Data.Function ((&)) @@ -40,13 +40,13 @@ lowerRule LowerPsuedoClasses { namespaces = ns, rewriteRules = rewrites } (Style StyleRule (lowerSelector ns rewrites sel) props pseudoel extractPseudoEl :: [Text] -> Selector -> Maybe Text -extractPseudoEl ps (Element sel) - | (pseudo:_) <- [p | Psuedoclass p [] <- sel, p `elem` ps] = Just pseudo - | otherwise = Nothing -extractPseudoEl ps (Child sel _) = extractPseudoEl ps sel -extractPseudoEl ps (Descendant sel _) = extractPseudoEl ps sel -extractPseudoEl ps (Adjacent sel _) = extractPseudoEl ps sel -extractPseudoEl ps (Sibling sel _) = extractPseudoEl ps sel +extractPseudoEl ps (Element sel) = extractPseudoEl' ps sel +extractPseudoEl ps (Child _ sel) = extractPseudoEl' ps sel +extractPseudoEl ps (Descendant _ sel) = extractPseudoEl' ps sel +extractPseudoEl ps (Adjacent _ sel) = extractPseudoEl' ps sel +extractPseudoEl ps (Sibling _ sel) = extractPseudoEl' ps sel +extractPseudoEl' :: [Text] -> [SimpleSelector] -> Maybe Text +extractPseudoEl' ps sel = listToMaybe [p | Psuedoclass p [] <- sel, p `elem` ps] lowerSelector :: HashMap Text Text -> HashMap Text [Token] -> Selector -> Selector lowerSelector ns rewrites (Element sel') = Element $ lowerSelector' ns rewrites sel' -- 2.30.2