flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pio...@apache.org
Subject [09/13] git commit: [flex-falcon] [refs/heads/feature/amf] - control which getter/setters get renamed by GCC by faking a set of externs. AFAICT that is what @export on the Object.defineProperties object did. It didn't actually create an export alias li
Date Sun, 13 Aug 2017 22:03:47 GMT
control which getter/setters get renamed by GCC by faking a set of externs.  AFAICT that is
what @export on the Object.defineProperties object did.  It didn't actually create an export
alias like exportSymbol per class, it just prevented renaming of the object keys with that
name


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/207a9587
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/207a9587
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/207a9587

Branch: refs/heads/feature/amf
Commit: 207a95872e4928a5af40209a6f436c51e7c14ace
Parents: 6331b80
Author: Alex Harui <aharui@apache.org>
Authored: Fri Aug 11 20:55:06 2017 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Aug 11 20:55:06 2017 -0700

----------------------------------------------------------------------
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java  | 45 ++++++++++++++++++++
 .../mxml/flexjs/MXMLFlexJSPublisher.java        | 36 ++++++++++++++++
 .../internal/projects/FlexJSProject.java        | 12 ++++++
 3 files changed, 93 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/207a9587/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
index c79bfea..5d29850 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
@@ -43,6 +43,7 @@ import org.apache.flex.compiler.constants.IASKeywordConstants;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.databinding.BindingDatabase;
 import org.apache.flex.compiler.internal.codegen.databinding.BindingInfo;
@@ -753,6 +754,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
             MXMLDescriptorSpecifier root = currentStateOverrides;
             root.isTopNode = true;
     
+            collectExportedNames(root);
+            
 	        writeNewline("/**");
 	        if (emitExports)
 	        	writeNewline(" * @export");
@@ -788,6 +791,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
             MXMLDescriptorSpecifier root = propertiesTree;
             root.isTopNode = true;
             writeNewline(root.output(true));
+            
+            collectExportedNames(root);
     
             write(ASEmitterTokens.SQUARE_CLOSE);
             write(ASEmitterTokens.PAREN_CLOSE);
@@ -1152,6 +1157,15 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         for (BindingInfo bi : bindingInfo)
         {
             String s;
+            IMXMLNode node = bi.node;
+            if (node instanceof IMXMLSingleDataBindingNode)
+            {
+            	IMXMLSingleDataBindingNode sbdn = (IMXMLSingleDataBindingNode)node;
+            	FlexJSProject project = (FlexJSProject)getMXMLWalker().getProject();
+            	IDefinition bdef = sbdn.getExpressionNode().resolve(project);
+            	IDefinition cdef = bdef.getParent();
+            	project.addExportedName(/*cdef.getQualifiedName() + "." + */bdef.getBaseName());
           	
+            }
             s = bi.getSourceString();
             if (s == null && bi.isSourceSimplePublicProperty())
                 s = getSourceStringFromGetter(bi.getExpressionNodesForGetter());
@@ -1652,6 +1666,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
             MXMLDescriptorSpecifier root = descriptorTree.get(0);
             root.isTopNode = false;
     
+            collectExportedNames(root);
+            
             indentPush();
             writeNewline("'MXMLDescriptor': {");
             writeNewline("/** @this {" + formatQualifiedName(cname) + "} */");
@@ -1697,6 +1713,35 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
    
     }
 
+    private void collectExportedNames(MXMLDescriptorSpecifier descriptor)
+    {
+        ICompilerProject project = getMXMLWalker().getProject();
+        FlexJSProject flexJSProject = null;
+        if (project instanceof FlexJSProject)
+        {
+            flexJSProject = (FlexJSProject) project;
+            String name = descriptor.name;
+            if (name == null)
+            	name = this.classDefinition.getQualifiedName();
+            for (MXMLDescriptorSpecifier prop : descriptor.propertySpecifiers)
+            {
+            	String propName = prop.name;
+            	flexJSProject.addExportedName(/*name + "." + */propName);
+            	if (prop.propertySpecifiers.size() > 0)
+            	{
+                    collectExportedNames(prop.propertySpecifiers.get(0));            		
+            	}
+            }
+            if (descriptor.childrenSpecifier != null)
+            {
+                for (MXMLDescriptorSpecifier prop : descriptor.childrenSpecifier.propertySpecifiers)
+                {
+                	collectExportedNames(prop);
+                }
+            }
+        }
+    }
+    
     //--------------------------------------------------------------------------    
 
     private HashMap<IMXMLEventSpecifierNode, String> eventHandlerNameMap = new HashMap<IMXMLEventSpecifierNode,
String>();

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/207a9587/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
index c0c382f..a46c9ba 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
@@ -266,6 +266,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
             compilerWrapper.addJSSourceFile(closureSourceFile);
         }
 
+        writeExportedNames(compilerWrapper);
 
         /////////////////////////////////////////////////////////////////////////////////
         // Add all the externs to the compilation
@@ -766,5 +767,40 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
         }
         return true;
     }
+    
+    private void writeExportedNames(JSClosureCompilerWrapper compilerWrapper)
+    {
+    	if (!googConfiguration.getExportPublicSymbols())
+    	{
+    		// if not generating exports for every public symbol
+    		// generate an externs file that blocks renaming
+    		// of properties used by MXML and dataBinding.
+	        Set<String> exportedNames = project.getExportedNames();
+	        if (exportedNames.size() > 0)
+	        {
+	        	StringBuilder sb = new StringBuilder();
+	        	sb.append("/**\n");
+	        	sb.append(" * generated by Apache FlexJS compiler\n");
+	        	sb.append(" * @externs\n");
+	        	sb.append(" */\n");
+	        	for (String name : exportedNames)
+	        	{
+	        		sb.append("\n\n");
+		        	sb.append("/**\n");
+		        	sb.append(" * @export\n");
+		        	sb.append(" */\n");
+		        	sb.append("Object.prototype." + name + ";\n");
+	        	}
+	        	File exportsFile = new File(outputFolder, "dontrename.js");
+	        	try {
+					writeFile(exportsFile, sb.toString(), false);
+				} catch (IOException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+	        	compilerWrapper.addJSExternsFile(exportsFile.getAbsolutePath());
+	        }
+    	}
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/207a9587/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java
index 8dc88b0..8c2b232 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java
@@ -21,6 +21,7 @@ package org.apache.flex.compiler.internal.projects;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -431,4 +432,15 @@ public class FlexJSProject extends FlexProject
 		return true;
 	}
 
+	private HashSet<String> exportedNames = new HashSet<String>();
+	
+	public void addExportedName(String name)
+	{
+		exportedNames.add(name);
+	}
+	
+	public Set<String> getExportedNames()
+	{
+		return exportedNames;
+	}
 }


Mime
View raw message