]> source.dussan.org Git - vaadin-framework.git/commitdiff
Warns and removes if parent reference '&' is used w/o parent, fixes #10327 47/347/3
authorMarc Englund <marc@vaadin.com>
Thu, 22 Nov 2012 14:02:27 +0000 (16:02 +0200)
committerMarc Englund <marc@vaadin.com>
Thu, 22 Nov 2012 14:18:13 +0000 (16:18 +0200)
Change-Id: I58eaf3f2acd27a7627c8df31e411a75fc4a48016

theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java
theme-compiler/tests/resources/css/parent-selector.css
theme-compiler/tests/resources/scss/parent-selector.scss

index 5f468446414dbcedb46b6c13de81784d4822ea58..216b03edbe153b91e00d3083505e50deb94f96e9 100644 (file)
@@ -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);
+    }
 }
index d128da0b4b95eb0b47349ff00b7fdddd8b745472..f8f893b8fddf88036b4d54726e86bf105ad792fd 100644 (file)
@@ -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();
index 1aa389f593c7519777c1d2b356a576caf937ec2d..2a73313f0c3bf9e378a0fccd46f1c7b3a9202686 100644 (file)
@@ -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
index c0ef46afb3eb424d21aebce01652b2cf8ec88094..74f0e15b9e6c064d90474efed131c208d3db6131 100644 (file)
@@ -46,4 +46,8 @@ a {
                        color: blue;
                }
        }
+}
+
+&.drop-parent-reference {
+       color: green;
 }
\ No newline at end of file