This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new 3f09ebc41 JSCSSCompilationSession: fix issues with generation of
selectors in real .css file where parts were incorrect or missing
3f09ebc41 is described below
commit 3f09ebc41206a2578745e14ba6d705b7c4b3b6a2
Author: Josh Tynjala <[email protected]>
AuthorDate: Thu Sep 25 14:13:07 2025 -0700
JSCSSCompilationSession: fix issues with generation of selectors in real
.css file where parts were incorrect or missing
---
.../driver/js/royale/JSCSSCompilationSession.java | 112 ++++++------------
.../test/resources/royale/files/CSSTestSource.css | 8 ++
.../royale/files/CSSTestSource_encoded_result.txt | 130 +++++++++++++++++++--
.../royale/files/CSSTestSource_result.css | 10 ++
.../apache/royale/compiler/css/ConditionType.java | 2 +-
5 files changed, 174 insertions(+), 88 deletions(-)
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 ebe902ce3..e98fb35e3 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.Collections;
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 @@ public class JSCSSCompilationSession extends
CSSCompilationSession
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 @@ public class JSCSSCompilationSession extends
CSSCompilationSession
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 2fb4dab0d..d23c64b31 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 @@ input + .innerMenu {
.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 6f9374a70..8def6dc56 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
@@ -18,16 +18,84 @@
//
////////////////////////////////////////////////////////////////////////////////
*/
-0, 1, ".glass", function() {this["borderColor"] = 7763059; this["fillAlphas"]
= [0.6000000238418579, 0.699999988079071, 0.800000011920929,
0.8999999761581421];
-this["fillColors"] = [8947848, 15987699, 10395294, 16579836];
this["highlightAlphas"] = [0.07000000029802322, 0.44999998807907104]},
-0, 1, ".glassSlider", function() {this["fillAlphas"] = [0.800000011920929,
0.699999988079071, 0.6000000238418579, 0.5];
-this["fillColors"] = [15987699, 12303291, 16579836, 13421772]}, 0, 1,
".listItem", function() {this["backgroundAlpha"] = 0.5;
+0,
+1,
+".glass",
+function() {this["borderColor"] = 7763059;
+this["fillAlphas"] = [0.6000000238418579, 0.699999988079071,
0.800000011920929, 0.8999999761581421];
+this["fillColors"] = [8947848, 15987699, 10395294, 16579836];
+this["highlightAlphas"] = [0.07000000029802322, 0.44999998807907104]},
+0,
+1,
+".glassSlider",
+function() {this["fillAlphas"] = [0.800000011920929, 0.699999988079071,
0.6000000238418579, 0.5];
+this["fillColors"] = [15987699, 12303291, 16579836, 13421772]},
+0,
+1,
+".listItem",
+function() {this["backgroundAlpha"] = 0.5;
this["backgroundColor"] = 16777215;
-this["borderStyle"] = "outset"; this["horizontalGap"] = 5.0;
this["paddingLeft"] = 4.0; this["paddingRight"] = 4.0; this["verticalAlign"] =
"middle"},
-0, 1, ".outer.inner", function() {this["width"] = 512.0}, 0, 1, ".outer
.inner", function() {this["width"] = 512.0}, 0, 1, ".outer>.innerTitle",
function() {this["background"] = ["url('assets/welcome_card.jpg')", "center",
"/", "cover"];
+this["borderStyle"] = "outset";
+this["horizontalGap"] = 5.0;
+this["paddingLeft"] = 4.0;
+this["paddingRight"] = 4.0;
+this["verticalAlign"] = "middle"},
+0,
+1,
+".outer.inner",
+function() {this["width"] = 512.0},
+0,
+1,
+".outer .inner",
+function() {this["width"] = 512.0},
+0,
+1,
+".outer>.innerTitle",
+function() {this["background"] = ["url('assets/welcome_card.jpg')", "center",
"/", "cover"];
this["color"] = 16777215;
-this["height"] = 176.0}, 0, 1, ".outer>.innerMenu", function() {this["color"]
= 16777215}, 0, 1, "h4", function() {this["color"] = 16777215}, 0, 1,
".outerother.inner", function() {this["height"] = 320.0; this["width"] =
320.0}, 0, 1, ".outerother-square>.innerTitle", function() {this["background"]
= ["url('assets/dog.png')", "bottom", "right", 15.0, "no-repeat", 4634284];
-this["color"] = 16777215}, 0, 1, ".usescalc", function() {this["color"] =
16777215; this["width"] = null}, 0, 1, ".FLEX35340A", function()
{this["background"] = null; this["filter"] = null; this["transform"] = null},
0, 1, ".FLEX35340B", function() {this["background"] = null}, 0, 1,
".FLEX35340C", function() {this["background"] = null}, 0, 1, ".FLEX35340D",
function() {this["boxShadow"] = ["0 2px 2px 0 rgba(0,0,0,.14)", "0 3px 1px -2px
rgba(0,0,0,.2)", "0 1px 5px 0 rgba(0,0,0,.12)"]; this["fontFamily"] =
["Georgia", "Times New Roman", "Times", "serif"];
+this["height"] = 176.0},
+0,
+1,
+".outer>.innerMenu",
+function() {this["color"] = 16777215},
+0,
+1,
+"h4",
+function() {this["color"] = 16777215},
+0,
+1,
+".outerother.inner",
+function() {this["height"] = 320.0;
+this["width"] = 320.0},
+0,
+1,
+".outerother-square>.innerTitle",
+function() {this["background"] = ["url('assets/dog.png')", "bottom", "right",
15.0, "no-repeat", 4634284];
+this["color"] = 16777215},
+0,
+1,
+".usescalc",
+function() {this["color"] = 16777215;
+this["width"] = null},
+0,
+1,
+".FLEX35340A",
+function() {this["background"] = null;
+this["filter"] = null;
+this["transform"] = null},
+0,
+1,
+".FLEX35340B",
+function() {this["background"] = null},
+0,
+1,
+".FLEX35340C",
+function() {this["background"] = null},
+0,
+1,
+".FLEX35340D",
+function() {this["boxShadow"] = ["0 2px 2px 0 rgba(0,0,0,.14)", "0 3px 1px
-2px rgba(0,0,0,.2)", "0 1px 5px 0 rgba(0,0,0,.12)"];
+this["fontFamily"] = ["Georgia", "Times New Roman", "Times", "serif"];
this["textShadow"] = [0.0, -1.0, 0.0, 2986344448]},
0,
1,
@@ -43,8 +111,46 @@ this["position"] = "absolute";
this["top"] = 50.0;
this["transform"] = null;
this["width"] = null},
-0, 1, "input", function() {this["padding"] = 0.0}, 0, 1,
"input[type=\"checkbox\"]", function() {this["padding"] = 0.0}, 0, 1,
".slider::-webkit-slider-thumb", function() {this["padding"] = 0.0}, 0, 1,
"input[type=\"range\"]", function() {this["content"] =
"assets/checkbox-tick.svg";
-this["padding"] = 0.0}, 0, 1, "input[type=\"range\"]", function()
{this["content"] = "✔"; this["padding"] = 0.0}, 0, 1, "input+.innerMenu",
function() {this["color"] = 16777215}, 0, 1,
-".complex", function() {this["background"] =
["url(\"data:image/svg+xml;utf8,<svg viewBox='0 0 16 13' version='1.1'
xmlns='http://www.w3.org/2000/svg'><g transform='translate(-763, -290)'><g
transform='translate(760, 285)'><g><polygon fill='#ffffff' points='3 13 9 18 19
7 16 5 9 13 6 10'></polygon></g></g></g></svg>\")", 11788282]},
-0, 1, ".blurfilter", function() {this["filter"] = null}];
+0,
+1,
+"input",
+function() {this["padding"] = 0.0},
+0,
+1,
+"input[type=\"checkbox\"]",
+function() {this["padding"] = 0.0},
+0,
+1,
+".slider::-webkit-slider-thumb",
+function() {this["padding"] = 0.0},
+0,
+1,
+"input[type=\"range\"]",
+function() {this["content"] = "assets/checkbox-tick.svg";
+this["padding"] = 0.0},
+0,
+1,
+"input[type=\"range\"]",
+function() {this["content"] = "✔";
+this["padding"] = 0.0},
+0,
+1,
+"input+.innerMenu",
+function() {this["color"] = 16777215},
+0,
+1,
+".complex",
+function() {this["background"] = ["url(\"data:image/svg+xml;utf8,<svg
viewBox='0 0 16 13' version='1.1' xmlns='http://www.w3.org/2000/svg'><g
transform='translate(-763, -290)'><g transform='translate(760,
285)'><g><polygon fill='#ffffff' points='3 13 9 18 19 7 16 5 9 13 6
10'></polygon></g></g></g></svg>\")", 11788282]},
+0,
+1,
+".blurfilter",
+function() {this["filter"] = null},
+0,
+1,
+"p:not(.primary)",
+function() {this["color"] = 16777215},
+0,
+1,
+"span.subtitle",
+function() {this["color"] = 16777215}];
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 f392718a7..5a847f95c 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 @@ input+.innerMenu {
}
+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 0457cc998..f538de4b3 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 @@ public enum ConditionType
/**
* For example: <code>s|Panel:not(:first-child)</code>
*/
- NOT("not"),
+ NOT(":not"),
/**
* For example: <code>s|Label[loadingState]</code>