JSCSSCompilationSession: fix issues with generation of selectors in real .css file where parts were incorrect or missing
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
index ebe902c..e98fb35 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
@@ -24,6 +24,8 @@
 import java.util.List;
 
 import org.apache.royale.compiler.constants.IASLanguageConstants;
+import org.apache.royale.compiler.css.ConditionType;
+import org.apache.royale.compiler.css.ICSSCombinator;
 import org.apache.royale.compiler.css.ICSSDocument;
 import org.apache.royale.compiler.css.ICSSMediaQueryCondition;
 import org.apache.royale.compiler.css.ICSSProperty;
@@ -167,82 +169,11 @@
         boolean firstOne = true;
         for (ICSSSelector selector : selectors)
         {
-        	String s = selector.toString();
-	        // add "." to type selectors that don't map cleanly
-	        // to CSS type selectors to convert them to class
-	    	// selectors.
-	        if (!s.startsWith(".") && !s.startsWith("*") && !s.startsWith("#") && !s.startsWith("::"))
-	        {
-	        	String condition = null;
-        		int colon = s.indexOf(":");
-	        	if (colon != -1)
-	        	{
-	        		condition = s.substring(colon);
-	        		s = s.substring(0, colon);
-	        	}
-	        	else
-	        	{
-	        		int brace = s.indexOf("[");
-	        		if (brace != -1)
-	        		{
-		        		condition = s.substring(brace);
-		        		s = s.substring(0, brace);	        			
-	        		}
-	        		else
-	        		{
-	        			int child = s.indexOf(">");
-	        			if (child != -1)
-	        			{
-			        		condition = s.substring(child);
-			        		s = s.substring(0, child);	        			
-	        			}
-	        			else
-	        			{
-	        				int preceded = s.indexOf("+");
-		        			if (preceded != -1)
-		        			{
-				        		condition = s.substring(preceded);
-				        		s = s.substring(0, preceded);	        			
-		        			}
-	        			}
-	        		}
-	        	}
-	        	if (!htmlElementNames.contains(s.toLowerCase()))
-	        	{
-	        		if (s.indexOf(" ") > 0)
-	        		{
-	        			String parts[] = s.split(" ");
-	        			int n = parts.length;
-	        			s = "";
-	        			for (int i = 0; i < n; i++)
-	        			{
-	        				if (i != 0)
-	        					s += " ";
-	        				String part = parts[i];
-	        				if (!part.startsWith(".") && !part.startsWith("*") && !part.startsWith("#") && !part.startsWith("::"))
-	        				{
-	        					int pipe = part.indexOf("|");
-				        		if (pipe != -1)
-				        			part = part.substring(pipe + 1);
-				        		part = "." + part;
-	        				}
-			        		s += part;
-	        			}
-	        		}
-	        		else
-	        		{
-		        		int pipe = s.indexOf("|");
-		        		if (pipe != -1)
-		        			s = s.substring(pipe + 1);
-		        		s = "." + s;
-	        		}
-	        	}
-	        	if (condition != null)
-	        		s = s + condition;
-	        }
-	        if (!firstOne)
+            if (firstOne)
+                firstOne = false;
+            else
 	        	result.append(",\n");
-	        result.append(s);
+            appendSelector(selector, result);
         }
 
         result.append(" {\n");
@@ -270,6 +201,37 @@
 
         return result.toString();
     }
+
+    private void appendSelector(ICSSSelector selector, StringBuilder builder)
+    {
+        ICSSCombinator combinator = selector.getCombinator();
+        if (combinator != null)
+        {
+            appendSelector(combinator.getSelector(), builder);
+            builder.append(combinator.getCombinatorType().text);
+        }
+        String elementName = selector.getElementName();
+        if (elementName != null)
+        {
+            if (!"*".equals(elementName))
+            {
+                String nsPrefix = selector.getNamespacePrefix();
+                if (nsPrefix != null)
+                {
+                    // add "." to type selectors that don't map cleanly
+                    // to CSS type selectors to convert them to class
+                    // selectors.
+                    builder.append(ConditionType.CLASS.prefix);
+                }
+            }
+            builder.append(elementName);
+        }
+        for (ICSSSelectorCondition condition : selector.getConditions())
+        {
+            builder.append(condition.getConditionType().prefix);
+            builder.append(condition.getValue());
+        }
+    }
     
     private void walkCSS(ICSSDocument css, StringBuilder sb)
     {
diff --git a/compiler-jx/src/test/resources/royale/files/CSSTestSource.css b/compiler-jx/src/test/resources/royale/files/CSSTestSource.css
index 2fb4dab..d23c64b 100755
--- a/compiler-jx/src/test/resources/royale/files/CSSTestSource.css
+++ b/compiler-jx/src/test/resources/royale/files/CSSTestSource.css
@@ -158,4 +158,12 @@
 
 .blurfilter {
   filter: blur(5px)
+}
+
+p:not(.primary) {
+  color: #fff;
+}
+
+#my-id ~ h1:first-child span.subtitle {
+  color: #fff;
 }
\ No newline at end of file
diff --git a/compiler-jx/src/test/resources/royale/files/CSSTestSource_encoded_result.txt b/compiler-jx/src/test/resources/royale/files/CSSTestSource_encoded_result.txt
index 6f9374a..8def6dc 100755
--- a/compiler-jx/src/test/resources/royale/files/CSSTestSource_encoded_result.txt
+++ b/compiler-jx/src/test/resources/royale/files/CSSTestSource_encoded_result.txt
Binary files differ
diff --git a/compiler-jx/src/test/resources/royale/files/CSSTestSource_result.css b/compiler-jx/src/test/resources/royale/files/CSSTestSource_result.css
index f392718..5a847f9 100755
--- a/compiler-jx/src/test/resources/royale/files/CSSTestSource_result.css
+++ b/compiler-jx/src/test/resources/royale/files/CSSTestSource_result.css
@@ -178,4 +178,14 @@
 }
 
 
+p:not(.primary) {
+        color: #fff;
+}
+
+
+#my-id~h1:first-child span.subtitle {
+        color: #fff;
+}
+
+
 
diff --git a/compiler/src/main/java/org/apache/royale/compiler/css/ConditionType.java b/compiler/src/main/java/org/apache/royale/compiler/css/ConditionType.java
index 0457cc9..f538de4 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/css/ConditionType.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/css/ConditionType.java
@@ -47,7 +47,7 @@
     /**
      * For example: <code>s|Panel:not(:first-child)</code>
      */
-    NOT("not"),
+    NOT(":not"),
 
     /**
      * For example: <code>s|Label[loadingState]</code>