~alcinnz/haskell-stylist

e8c6873fadef9acde6aa204599a1adad5cb0947d — Adrian Cochrane 5 years ago b6808a6
Data.CSS.Style.Selector.Index: fix potential crash.
1 files changed, 10 insertions(+), 9 deletions(-)

M src/Data/CSS/Style/Selector/Index.hs
M src/Data/CSS/Style/Selector/Index.hs => src/Data/CSS/Style/Selector/Index.hs +10 -9
@@ 41,17 41,18 @@ simpleSelector (Descendant _ s) = s
simpleSelector (Adjacent _ s) = s
simpleSelector (Sibling _ s) = s

addRuleForSelector self rule [] = self {unindexed = rule : unindexed self}
addRuleForSelector self rule selector = self {
addRuleForSelector self@(StyleIndex index _) rule selector
  | Just key <- selectorKey selector = self {
        indexed = insert key (rule : lookup' key index) index
    } where
        key = selectorKey selector
        index = indexed self
    }
  | otherwise = self {unindexed = rule : unindexed self}

selectorKey (tok@(Tag _) : _) = tok
selectorKey (tok@(Id _) : _) = tok
selectorKey (tok@(Class _) : _) = tok
selectorKey (Property prop _ : _) = Property prop Exists
selectorKey (tok@(Tag _) : _) = Just tok
selectorKey (tok@(Id _) : _) = Just tok
selectorKey (tok@(Class _) : _) = Just tok
selectorKey (Property prop _ : _) = Just $ Property prop Exists
--selectorKey (_ : tokens) = selectorKey tokens
selectorKey [] = Nothing

----