You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2025/04/17 22:56:38 UTC

(royale-compiler) branch develop updated (e7b7f07a6 -> 70c41c39f)

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


    from e7b7f07a6 JSCSSCompilationSession: fix font-weight incorrectly output with font-style value
     new 60af8943a JSRoyaleASDocEmitter: instead of skipping certain fields, output valid empty values instead
     new 70c41c39f JSRoyaleASDocEmitter: improve escaping of asdoc tag descriptions

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../codegen/js/royale/JSRoyaleASDocEmitter.java    | 203 +++++++++------------
 1 file changed, 88 insertions(+), 115 deletions(-)


(royale-compiler) 02/02: JSRoyaleASDocEmitter: improve escaping of asdoc tag descriptions

Posted by jo...@apache.org.
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

commit 70c41c39fe49a87f97f48779ee82968147b0037f
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Apr 17 15:29:26 2025 -0700

    JSRoyaleASDocEmitter: improve escaping of asdoc tag descriptions
    
    In particular, anything that should be escaped in a JSON string, but also a bit of normalization too
---
 .../codegen/js/royale/JSRoyaleASDocEmitter.java    | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
index 580121d84..f5c368904 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
@@ -626,10 +626,31 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
     					firstOne = false;
     					write("\"");
     					d = value.getDescription().trim();
-    					d = d.replace("\t", " ");
-    					d = d.replace("\\\"", "&quot;");
+
+						// escape all backslashes first because we might add
+						// more backslashes when we escape other stuff
+						// and we don't want to double escape those backslashes
     					d = d.replace("\\", "\\\\");
-    					write(d);
+
+						// we're wrapping the string with double quotes, so
+						// escape any double quotes that will appear inside them
+    					d = d.replace("\"", "\\\"");
+    					
+						// collapse tabs to spaces
+						d = d.replace("\t", " ");
+
+						// convert all other types of new lines to \n for consistency
+    					d = d.replace("\r\n", "\n");
+    					d = d.replace("\r", "\n");
+
+						// then escape all new lines
+    					d = d.replace("\n", "\\n");
+
+						// these characters don't make sense, so remove them
+						d = d.replace("\b", "");
+    					d = d.replace("\f", "");
+
+						write(d);
     					write("\"");
     				}
     			}


(royale-compiler) 01/02: JSRoyaleASDocEmitter: instead of skipping certain fields, output valid empty values instead

Posted by jo...@apache.org.
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

commit 60af8943a697b3d7598237edab80f9b9a721bd83
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Apr 17 14:34:02 2025 -0700

    JSRoyaleASDocEmitter: instead of skipping certain fields, output valid empty values instead
    
    The ASDoc app uses JSONReviver, which needs those fields to exist so that it can generate the correct key to figure out which class to instantiate.
---
 .../codegen/js/royale/JSRoyaleASDocEmitter.java    | 176 ++++++++-------------
 1 file changed, 64 insertions(+), 112 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
index bb2bc02cb..580121d84 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleASDocEmitter.java
@@ -117,11 +117,8 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         write(formatQualifiedName(node.getQualifiedName()));
         writeNewline("\"");
         indentPush();
-        if (asDoc != null)
-        {
-            writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         indentPop();
         writeNewline("}");
     }
@@ -251,49 +248,34 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         else
         	write(formatQualifiedName(node.getBaseClassName()));
         writeNewline("\"");
-        if (asDoc != null)
-        {
-            writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         final IDefinitionNode[] members = node.getAllMemberNodes();
-        if (members.length > 0)
-        {
-        	writeNewline(",");
-        	writeNewline("\"members\": [");
-        	indentPush();
-        	indentPush();
-        }
+		writeNewline(",");
+		writeNewline("\"members\": [");
+		indentPush();
+		indentPush();
         firstMember = true;
         for (IDefinitionNode mnode : members)
         {
         	getWalker().walk(mnode);
         }
-        if (members.length > 0)
-        {
-            indentPop();
-            indentPop();
-        	writeNewline("]");
-        }
+		indentPop();
+		indentPop();
+		writeNewline("]");
         IMetaTagNode[] metas = node.getMetaTagNodesByName("Event");
-        if (metas.length > 0)
-        {
-        	writeNewline(",");
-        	writeNewline("\"events\": [");
-        	indentPush();
-        	indentPush();
-        }
+		writeNewline(",");
+		writeNewline("\"events\": [");
+		indentPush();
+		indentPush();
         firstMember = true;
         for (IMetaTagNode mnode : metas)
         {
         	writeEventTagNode(mnode);
         }
-        if (metas.length > 0)
-        {
-            indentPop();
-            indentPop();
-        	writeNewline("]");
-        }
+		indentPop();
+		indentPop();
+		writeNewline("]");
         
         indentPop();
         writeNewline("}");
@@ -317,43 +299,31 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         write(formatQualifiedName(node.getQualifiedName()));
         write("\"");
         IExpressionNode bases[] = node.getExtendedInterfaceNodes();
-        if (bases.length > 0)
-        {
-            writeNewline(",");
-            writeNewline("\"baseInterfaceNames\": [");
-            boolean firstBase = true;
-            int n = bases.length;
-	        for (int i = 0; i < n; i++)
-	        {
-	        	if (!firstBase)
-	        		writeNewline(", ");
-	        	firstBase = false;
-	        	IDefinition baseDef = bases[i].resolve(getWalker().getProject());
-	        	write("\"" + formatQualifiedName(baseDef.getQualifiedName()) + "\"");
-	        }
-        	writeNewline("]");
-        }
+		writeNewline(",");
+		writeNewline("\"baseInterfaceNames\": [");
+		boolean firstBase = true;
+		int n = bases.length;
+		for (int i = 0; i < n; i++)
+		{
+			if (!firstBase)
+				writeNewline(", ");
+			firstBase = false;
+			IDefinition baseDef = bases[i].resolve(getWalker().getProject());
+			write("\"" + formatQualifiedName(baseDef.getQualifiedName()) + "\"");
+		}
+		writeNewline("]");
         indentPush();
-        if (asDoc != null)
-        {
-        	writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         final IDefinitionNode[] members = node.getAllMemberDefinitionNodes();
-        if (members.length > 0)
-        {
-        	writeNewline(",");
-        	writeNewline("\"members\": [");
-        }
+		writeNewline(",");
+		writeNewline("\"members\": [");
         firstMember = true;
         for (IDefinitionNode mnode : members)
         {
         	getWalker().walk(mnode);
         }
-        if (members.length > 0)
-        {
-        	writeNewline("]");
-        }
+		writeNewline("]");
         indentPop();
         writeNewline("}");
         addToIndex(node.getDefinition(), asDoc);
@@ -405,11 +375,8 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         writeNewline("\",");
         writeDefinitionAttributes(def);
         indentPush();
-        if (asDoc != null)
-        {
-            writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         indentPop();
         write("}");
         addToIndex(node.getDefinition(), asDoc);
@@ -451,11 +418,8 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         writeNewline("\",");
         writeDefinitionAttributes(def);
         indentPush();
-        if (asDoc != null)
-        {
-            writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         indentPop();
         write("}");
         addToIndex(node.getDefinition(), asDoc);
@@ -481,11 +445,8 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         writeNewline("\",");
         writeDefinitionAttributes(node.getDefinition());
         indentPush();
-        if (asDoc != null)
-        {
-            writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         indentPop();
         write("}");
         addToIndex(node.getDefinition(), asDoc);
@@ -508,11 +469,8 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         writeNewline("\",");
         writeDefinitionAttributes(node.getDefinition());
         indentPush();
-        if (asDoc != null)
-        {
-            writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         indentPop();
         write("}");
         addToIndex(node.getDefinition(), asDoc);
@@ -555,11 +513,8 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         writeNewline("\",");
         writeDefinitionAttributes(def);
         indentPush();
-        if (asDoc != null)
-        {
-            writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         indentPop();
         write("}");
         addToIndex(node.getDefinition(), asDoc);
@@ -584,11 +539,8 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         writeDefinitionAttributes(node.getDefinition());
         indentPush();
         writeNewline(",");
-        if (asDoc != null)
-        {
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-            writeNewline(",");
-        }
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
+		writeNewline(",");
         write("  \"return\": \"");
         if (node.getReturnType().equals("void"))
 		{
@@ -630,21 +582,24 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
     public void writeASDoc(ASDocComment asDoc, RoyaleASDocProject project)
     {
     	List<String> tagList = project.tags;
-    	asDoc.compile();
+		if (asDoc != null)
+		{
+    		asDoc.compile();
+		}
         write("  \"description\": \"");
-        String d = asDoc.getDescription();
+        String d = asDoc != null ? asDoc.getDescription() : "";
 		d = d.replace("\t", " ");
 		d = d.replace("\\\"", "&quot;");
 		d = d.replace("\\", "\\\\");
     	write(d);
 		write("\"");
-    	Map<String, List<IASDocTag>> tags = asDoc.getTags();
+    	Map<String, List<IASDocTag>> tags = asDoc != null ? asDoc.getTags() : null;
+		writeNewline(",");
+		writeNewline("\"tags\": [");
+		indentPush();
+		indentPush();
     	if (tags != null)
     	{
-    		writeNewline(",");
-    		writeNewline("\"tags\": [");
-    		indentPush();
-    		indentPush();
     		boolean firstTag = true;
     		Set<String> tagNames = tags.keySet();
     		for (String tagName : tagNames)
@@ -682,10 +637,10 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         		indentPop();
         		indentPop();
     		}
-    		write("  ]");
-    		indentPop();
-    		indentPop();
-    	}
+		}
+		write("  ]");
+		indentPop();
+		indentPop();
     }
            
     public void writeDefinitionAttributes(IDefinition def)
@@ -799,11 +754,8 @@ public class JSRoyaleASDocEmitter extends JSRoyaleEmitter implements IJSRoyaleAS
         write(evt.getValue("type"));
         writeNewline("\"");
         indentPush();
-        if (asDoc != null)
-        {
-            writeNewline(",");
-        	writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
-        }
+		writeNewline(",");
+		writeASDoc(asDoc, (RoyaleASDocProject)getWalker().getProject());
         indentPop();
         write("}");
         addToIndex(evt.getDefinition(), asDoc);