diff options
author | Henri Sara <hesara@vaadin.com> | 2012-11-22 14:19:04 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-11-22 14:19:04 +0000 |
commit | e33302b9676ae62ea0bdc53ff6c6e3f4aea01522 (patch) | |
tree | 35786b58302101157b36a9beeed4613d7374b79c | |
parent | 7c22ebd68c71cd88b4bc42438df778c7c20e4aae (diff) | |
parent | b913ab2907b9976e9844d77bb15ff14ac612d870 (diff) | |
download | vaadin-framework-e33302b9676ae62ea0bdc53ff6c6e3f4aea01522.tar.gz vaadin-framework-e33302b9676ae62ea0bdc53ff6c6e3f4aea01522.zip |
Merge "Warns and removes if parent reference '&' is used w/o parent, fixes #10327"
4 files changed, 37 insertions, 0 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java index 5f46844641..216b03edbe 100644 --- a/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java +++ b/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.logging.Logger; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; @@ -250,4 +251,7 @@ public class ScssStylesheet extends Node { return lastNodeAdded; } + public static final void warning(String msg) { + Logger.getLogger(ScssStylesheet.class.getName()).warning(msg); + } } diff --git a/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java index d128da0b4b..f8f893b8fd 100644 --- a/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java +++ b/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java @@ -61,9 +61,34 @@ public class BlockNodeHandler { if (parent instanceof BlockNode) { combineParentSelectorListToChild(node); + + } else if (node.getSelectors().contains("&")) { + ScssStylesheet.warning("Base-level rule contains" + + " the parent-selector-referencing character '&';" + + " the character will be removed:\n" + node); + removeParentReference(node); } } + /** + * Goes through the selector list of the given BlockNode and removes the '&' + * character from the selectors. + * + * @param node + */ + private static void removeParentReference(BlockNode node) { + ArrayList<String> newList = new ArrayList<String>(); + for (String childSelector : node.getSelectorList()) { + // remove parent selector + if (childSelector.contains("&")) { + newList.add(childSelector.replace("&", "")); + } else { + newList.add(childSelector); + } + } + node.setSelectorList(newList); + } + private static void combineParentSelectorListToChild(BlockNode node) { ArrayList<String> newList = new ArrayList<String>(); BlockNode parentBlock = (BlockNode) node.getParentNode(); diff --git a/theme-compiler/tests/resources/css/parent-selector.css b/theme-compiler/tests/resources/css/parent-selector.css index 1aa389f593..2a73313f0c 100644 --- a/theme-compiler/tests/resources/css/parent-selector.css +++ b/theme-compiler/tests/resources/css/parent-selector.css @@ -41,4 +41,8 @@ body.firefox a { .root2 .part .one, .root2 .part .non-parent, .root2 .part2 .one, .root2 .part2 .non-parent { color: blue; +} + +.drop-parent-reference { + color: green; }
\ No newline at end of file diff --git a/theme-compiler/tests/resources/scss/parent-selector.scss b/theme-compiler/tests/resources/scss/parent-selector.scss index c0ef46afb3..74f0e15b9e 100644 --- a/theme-compiler/tests/resources/scss/parent-selector.scss +++ b/theme-compiler/tests/resources/scss/parent-selector.scss @@ -46,4 +46,8 @@ a { color: blue; } } +} + +&.drop-parent-reference { + color: green; }
\ No newline at end of file |