Skip to content

Commit

Permalink
Merge pull request #143 from tolgap/fix_mixed_nesting
Browse files Browse the repository at this point in the history
Fix properties not resolving after or inbetween an ExtendSelector and/or WithPseudoElement
  • Loading branch information
Richard Feldman authored Jul 22, 2016
2 parents e7ab020 + c5f68fb commit 6c7a0cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Css/Preprocess/Resolve.elm
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,26 @@ applyNestedMixinsToLast nestedMixins rest f declarations =
withoutParent decls =
List.tail decls
|> Maybe.withDefault []

{- We recreate the declarations if necessary. It is possible that
there was an `AppendProperty` in between two `ExtendSelectors` or two `WithPseudoElements`
or an `AppendProperty` after an `ExtendSelector` or `WithPseudoElement`.
-}
newDeclarations =
case ( List.head nextResult.declarations, List.head <| List.reverse declarations ) of
( Just nextResultParent, Just originalParent ) ->
List.take (List.length declarations - 1) declarations
++ [ if originalParent /= nextResultParent then
nextResultParent
else
originalParent
]

_ ->
declarations
in
{ warnings = initialResult.warnings ++ nextResult.warnings
, declarations = declarations ++ (withoutParent initialResult.declarations ) ++ (withoutParent nextResult.declarations)
, declarations = newDeclarations ++ (withoutParent initialResult.declarations) ++ (withoutParent nextResult.declarations)
}


Expand Down
2 changes: 2 additions & 0 deletions test/Fixtures.elm
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ pseudoElementStylesheet =
[ color (hex "#fff") ]
, after
[ color (hex "#000") ]
, color (hex "#aaa")
]
]

Expand All @@ -368,5 +369,6 @@ pseudoClassStylesheet =
[ fontSize (em 3) ]
, disabled
[ marginTop (px 20) ]
, backgroundColor (hex "#aaa")
]
]
2 changes: 2 additions & 0 deletions test/Tests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ pseudoElements =
"""
#Page {
margin: 10px;
color: #aaa;
}
#Page::before {
Expand Down Expand Up @@ -624,6 +625,7 @@ pseudoClasses =
"""
#Page {
color: #fff;
background-color: #aaa;
}
#Page:hover {
Expand Down

0 comments on commit 6c7a0cc

Please sign in to comment.