]> source.dussan.org Git - vaadin-framework.git/commitdiff
(#10182) Rule order not preserved when using parent reference in sass 77/277/1
authorSebastian Nyholm <sebastian@vaadin.com>
Thu, 15 Nov 2012 12:33:28 +0000 (14:33 +0200)
committerSebastian Nyholm <sebastian@vaadin.com>
Thu, 15 Nov 2012 12:51:42 +0000 (14:51 +0200)
Change-Id: Ief701eef3a262c4fd0c14241c54b3d57cb858027

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

index 45578deb195639e2e98d0119bdf82a6be78a2268..5f468446414dbcedb46b6c13de81784d4822ea58 100644 (file)
@@ -38,7 +38,6 @@ import com.vaadin.sass.tree.Node;
 import com.vaadin.sass.tree.VariableNode;
 import com.vaadin.sass.tree.controldirective.IfElseDefNode;
 import com.vaadin.sass.visitor.ImportNodeHandler;
-import com.vaadin.sass.visitor.ParentSelectorHandler;
 
 public class ScssStylesheet extends Node {
 
@@ -52,6 +51,8 @@ public class ScssStylesheet extends Node {
 
     private static final HashSet<IfElseDefNode> ifElseDefNodes = new HashSet<IfElseDefNode>();
 
+    private static HashMap<Node, Node> lastNodeAdded = new HashMap<Node, Node>();
+
     private String fileName;
 
     /**
@@ -130,7 +131,7 @@ public class ScssStylesheet extends Node {
         mixinDefs.clear();
         variables.clear();
         ifElseDefNodes.clear();
-        ParentSelectorHandler.clear();
+        lastNodeAdded.clear();
         importOtherFiles(this);
         populateDefinitions(this);
         traverse(this);
@@ -245,4 +246,8 @@ public class ScssStylesheet extends Node {
         return fileName;
     }
 
+    public static HashMap<Node, Node> getLastNodeAdded() {
+        return lastNodeAdded;
+    }
+
 }
index d338cb084325099e1b3f884d65ae8b0259f37e0d..0d00fd2d0c47c5599b7d3db91190fe755f0e74e6 100644 (file)
@@ -19,13 +19,12 @@ package com.vaadin.sass.visitor;
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.tree.BlockNode;
 import com.vaadin.sass.tree.Node;
 
 public class BlockNodeHandler {
 
-    private static HashMap<Node, Node> lastNodeAdded = new HashMap<Node, Node>();
-
     public static void traverse(BlockNode node) {
 
         Node parent = node.getParentNode();
@@ -61,6 +60,7 @@ public class BlockNodeHandler {
         }
         node.setSelectorList(newList);
         Node oldParent = node.getParentNode();
+        HashMap<Node, Node> lastNodeAdded = ScssStylesheet.getLastNodeAdded();
         if (lastNodeAdded.get(oldParent) != null) {
             node.getParentNode().getParentNode()
                     .appendChild(node, lastNodeAdded.get(oldParent));
index 4098cc7cadb012e7069a9aac731984adaa205b0b..cb7b0ac8a89ca5ed2c22355dcfe4347c0772348d 100644 (file)
@@ -19,13 +19,12 @@ package com.vaadin.sass.visitor;
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.tree.BlockNode;
 import com.vaadin.sass.tree.Node;
 
 public class ParentSelectorHandler {
 
-    private static HashMap<Node, Node> parentSelectors = new HashMap<Node, Node>();
-
     public static void traverse(BlockNode block) throws Exception {
         Node parentNode = block.getParentNode();
         if (parentNode instanceof BlockNode) {
@@ -48,22 +47,20 @@ public class ParentSelectorHandler {
             if (isParentSelector) {
                 block.setSelectorList(newList);
                 Node oldparent = block.getParentNode();
-                if (parentSelectors.containsKey(block.getParentNode())) {
+                HashMap<Node, Node> lastNodeAdded = ScssStylesheet
+                        .getLastNodeAdded();
+                if (lastNodeAdded.containsKey(block.getParentNode())) {
                     block.getParentNode()
                             .getParentNode()
                             .appendChild(block,
-                                    parentSelectors.get(block.getParentNode()));
+                                    lastNodeAdded.get(block.getParentNode()));
                 } else {
                     block.getParentNode().getParentNode()
                             .appendChild(block, block.getParentNode());
                 }
 
-                parentSelectors.put(oldparent, block);
+                lastNodeAdded.put(oldparent, block);
             }
         }
     }
-
-    public static void clear() {
-        parentSelectors.clear();
-    }
 }
index 0330782fbfcb7b1829b610443e63821c7da71df5..e7e37e92abedea301cc8ab95b2b0dc9e51dee158 100644 (file)
@@ -3,6 +3,10 @@ a {
        text-decoration: none;
 }
 
+a .sub {
+       color: blue;
+}
+
 a:hover {
        text-decoration: underline;
 }
index ee02f8bf769bc5522257563db2532d819856be49..68f66a4a2756693074d88c9afc78ee548905bebf 100644 (file)
@@ -1,6 +1,9 @@
 a {
   font-weight: bold;
   text-decoration: none;
+  .sub {
+       color: blue;
+  }
   &:hover { text-decoration: underline; }
   body.firefox & { font-weight: normal; }
 }
index e1e1fee3b4919eabfdc60f71fc0e462e8e295087..ebe62fd678862f1d8500d6b50220334b1135d7a3 100644 (file)
@@ -41,10 +41,10 @@ public class ParentSelector extends AbstractTestBase {
         parser.parseStyleSheet(getClass().getResource(scss).getPath());
         ScssStylesheet root = handler.getStyleSheet();
         BlockNode blockNode = (BlockNode) root.getChildren().get(0);
-        Assert.assertEquals(4, blockNode.getChildren().size());
-        BlockNode nestedBlock1 = (BlockNode) blockNode.getChildren().get(2);
+        Assert.assertEquals(5, blockNode.getChildren().size());
+        BlockNode nestedBlock1 = (BlockNode) blockNode.getChildren().get(3);
         Assert.assertEquals("&:hover", nestedBlock1.getSelectorList().get(0));
-        BlockNode nestedBlock2 = (BlockNode) blockNode.getChildren().get(3);
+        BlockNode nestedBlock2 = (BlockNode) blockNode.getChildren().get(4);
         Assert.assertEquals("body.firefox &", nestedBlock2.getSelectorList()
                 .get(0));
     }