You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2022/01/12 07:08:09 UTC

[royale-compiler] branch ReleaseModules created (now a06255f)

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

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


      at a06255f  get release modules to work by removing package initialization from modules that shouldn't be there, by using Closure Compiler for externs reports, and adding Language APIs to the externs report

This branch includes the following new commits:

     new 29eea23  revert back to original passes
     new d27c834  move externs reporting to Closure Compiler.  It knows how to produce a much better set of externs
     new 5a60e41  get release modules to work by preventing rename of superClass_ in base.js, and by excluding compilation of files excluded from the module
     new b862687  add option to prevent renaming some object keys
     new f7634af  don't bring in files for modules that were in the app, rename object keys in files, and prevent renaming of Language APIs if outputting a module
     new a06255f  get release modules to work by removing package initialization from modules that shouldn't be there, by using Closure Compiler for externs reports, and adding Language APIs to the externs report

The 6 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.


[royale-compiler] 04/06: add option to prevent renaming some object keys

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch ReleaseModules
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit b86268705764d21b4d4e465377f9ab7f43e47d9c
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Jan 11 00:51:31 2022 -0800

    add option to prevent renaming some object keys
---
 .../internal/driver/js/goog/JSGoogConfiguration.java  | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
index 009ea52..1ef218c 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
@@ -884,6 +884,25 @@ public class JSGoogConfiguration extends JSConfiguration
 
     
     //
+    // 'prevent-rename-object-keys'
+    //
+
+    private String preventRenameObjectKeys = null;
+
+    public String getPreventRenameObjectKeys()
+    {
+        return preventRenameObjectKeys;
+    }
+
+    @Config
+    @Mapping("prevent-rename-object-keys")
+    public void setPreventRenameObjectKeys(ConfigurationValue cv, String value)
+            throws ConfigurationException
+    {
+    	preventRenameObjectKeys = value;
+    }
+
+    //
     // 'allow-dynamic-bindings'
     //
 

[royale-compiler] 05/06: don't bring in files for modules that were in the app, rename object keys in files, and prevent renaming of Language APIs if outputting a module

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch ReleaseModules
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit f7634afdcf57069ba42ba53081a1ebab9b364cfe
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Jan 11 00:55:23 2022 -0800

    don't bring in files for modules that were in the app, rename object keys in files, and prevent renaming of Language APIs if outputting a module
---
 .../compiler/internal/graph/GoogDepsWriter.java    | 91 +++++++++++++++++++---
 1 file changed, 82 insertions(+), 9 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
index ec9d248..fa0d7a0 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
@@ -67,6 +67,7 @@ public class GoogDepsWriter {
 		this.outputFolderPath = outputFolder.getAbsolutePath();
 		this.moduleOutput = config.getModuleOutput();
 		this.mainName = mainClassName;
+		this.externsReporting = config.getExternsReport() != null;
 		removeCirculars = config.getRemoveCirculars();
 		sourceMaps = config.getSourceMap();
 		sourceMapsSourceRoot = config.getSourceMapSourceRoot();
@@ -81,8 +82,11 @@ public class GoogDepsWriter {
 				System.out.println("using SWC: " + swc.getSWCFile().getAbsolutePath());
 			}
 		}
+		preventRenameObjectKeys = config.getPreventRenameObjectKeys();
 	}
 	
+    private String preventRenameObjectKeys = null;
+    private boolean externsReporting = false;
 	private ProblemQuery problems;
 	private String moduleOutput;
 	private String outputFolderPath;
@@ -102,6 +106,7 @@ public class GoogDepsWriter {
 	private HashMap<String, GoogDep> depMap = new HashMap<String,GoogDep>();
 	private HashMap<String, ICompilationUnit> requireMap = new HashMap<String, ICompilationUnit>();
 	private HashMap<ICompilationUnit, String> requireMap2 = new HashMap<ICompilationUnit, String>();
+	public  HashMap<String, String> providedMap = new HashMap<String, String>();
 	
 	public boolean needCSS = false;
 	
@@ -712,6 +717,11 @@ public class GoogDepsWriter {
 					}
 				}
 			}
+			String[] preventRenameKeys = null;
+            if (preventRenameObjectKeys != null)
+            {
+            	preventRenameKeys = preventRenameObjectKeys.split(",");
+            }
 
 			// first scan requires in case this is a module and some have been externed
 			int j = main.fileInfo.googProvideLine + 1;
@@ -725,7 +735,7 @@ public class GoogDepsWriter {
 				int c = line.indexOf(JSGoogEmitterTokens.GOOG_REQUIRE.getToken());
 				int c2 = line.indexOf(")");
                 String s = line.substring(c + 14, c2 - 1);
-                if (!isGoogProvided(s))
+                if (!isGoogProvided(s) || isExternal(s))
                 {
                 	fileLines.remove(j);
 					sourceMapConsumer = SourceMapUtils.removeLineFromSourceMap(sourceMapConsumer, mainFile.getName(), j);
@@ -734,21 +744,59 @@ public class GoogDepsWriter {
 				{
 					j++;
 				}
+                if (preventRenameKeys != null)
+                {
+                	boolean lineChanged = false;
+                	for (String key : preventRenameKeys)
+                	{
+                		if (line.contains("." + key))
+                		{
+                			lineChanged = true;
+                			line = line.replaceAll("\\." + key, "[\"" + key + "\"]");
+                		}
+                		if (line.contains(" " + key + ":"))
+                		{
+                			lineChanged = true;
+                			line = line.replace(" " + key + ":", " '" + key + "':");
+                		}
+                	}
+                	if (lineChanged)
+                		fileLines.set(j, line);
+                }
 			}
 			
 			int n = restOfDeps.size();
 			for (int i = n - 1; i >= 0; i--)
 			{
 				String dep = restOfDeps.get(i);
-				StringBuilder lineBuilder = new StringBuilder();
-				lineBuilder.append(JSGoogEmitterTokens.GOOG_REQUIRE.getToken())
-					.append("('")
-					.append(dep)
-					.append("');");
-				fileLines.add(main.fileInfo.googProvideLine + 1, lineBuilder.toString());
-				sourceMapConsumer = SourceMapUtils.addLineToSourceMap(sourceMapConsumer, mainFile.getName(), main.fileInfo.googProvideLine + 1);
+				if (!isExternal(dep))
+				{
+					StringBuilder lineBuilder = new StringBuilder();
+					lineBuilder.append(JSGoogEmitterTokens.GOOG_REQUIRE.getToken())
+						.append("('")
+						.append(dep)
+						.append("');");
+					fileLines.add(main.fileInfo.googProvideLine + 1, lineBuilder.toString());
+					sourceMapConsumer = SourceMapUtils.addLineToSourceMap(sourceMapConsumer, mainFile.getName(), main.fileInfo.googProvideLine + 1);
+				}
 			}
 
+			if (externsReporting)
+			{
+				// Anything added here needs to be added to JSClosureCompilerWrapper.
+				// This exports it, but also needs to be in externs
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"] = org.apache.royale.utils.Language;");				
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"][\"as\"] = org.apache.royale.utils.Language.as;");				
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"][\"_int\"] = org.apache.royale.utils.Language._int;");				
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"][\"string\"] = org.apache.royale.utils.Language.string;");				
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"][\"is\"] = org.apache.royale.utils.Language.is;");		
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"][\"uint\"] = org.apache.royale.utils.Language.uint;");				
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"][\"closure\"] = org.apache.royale.utils.Language.closure;");				
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"][\"sort\"] = org.apache.royale.utils.Language.sort;");		
+				fileLines.add("window[\"org\"][\"apache\"][\"royale\"][\"utils\"][\"Language\"][\"sortOn\"] = org.apache.royale.utils.Language.sortOn;");		
+			}
+			//fileLines.add("org.apache.royale.html.Group()");
+
 			FileUtils.writeLines(mainFile, "utf8", fileLines);
 
 			if (sourceMapConsumer != null)
@@ -784,6 +832,7 @@ public class GoogDepsWriter {
 			fileLines = Files.readLines(new File(gd.filePath), Charset.forName("utf8"));
             FileInfo fi = getFileInfo(fileLines, className);
 			gd.fileInfo = fi;
+			providedMap.put(gd.filePath, className);
 		} catch (IOException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
@@ -864,12 +913,36 @@ public class GoogDepsWriter {
         	int lastRequireLine = -1;
             FileInfo fi = gd.fileInfo;
 //            int suppressCount = 0;
+			String[] preventRenameKeys = null;
+            if (preventRenameObjectKeys != null)
+            {
+            	preventRenameKeys = preventRenameObjectKeys.split(",");
+            }
             int i = 0;
             int stopLine = fi.constructorLine;
             if (fi.constructorLine == -1) // standalone functions
             	stopLine = fi.googProvideLine + 4; // search a few more lines after goog.provide
             for (String line : fileLines)
             {
+                if (preventRenameKeys != null)
+                {
+                	boolean lineChanged = false;
+                	for (String key : preventRenameKeys)
+                	{
+                		if (line.contains("." + key))
+                		{
+                			lineChanged = true;
+                			line = line.replaceAll("\\." + key, "[\"" + key + "\"]");
+                		}
+                		if (line.contains(" " + key + ":"))
+                		{
+                			lineChanged = true;
+                			line = line.replace(" " + key + ":", " '" + key + "':");
+                		}
+                	}
+                	if (lineChanged)
+                		fileLines.set(i, line);
+                }
             	if (i < stopLine)
             	{
                     int c = line.indexOf(JSGoogEmitterTokens.ROYALE_DEPENDENCY_LIST.getToken());
@@ -886,7 +959,7 @@ public class GoogDepsWriter {
                         String s = line.substring(c + 14, c2 - 1);
                         if (((gd.fileInfo.impls == null || !gd.fileInfo.impls.contains(s)) &&
                         		(gd.fileInfo.staticDeps == null || !gd.fileInfo.staticDeps.contains(s))) ||
-                        		!isGoogProvided(s))
+                        		!isGoogProvided(s) || isExternal(s))
                         {
                         	// don't remove the require if some class needs it at static initialization
                         	// time

[royale-compiler] 06/06: get release modules to work by removing package initialization from modules that shouldn't be there, by using Closure Compiler for externs reports, and adding Language APIs to the externs report

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch ReleaseModules
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit a06255f461f10465f689445c369fde4bb2d7c56d
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Jan 11 00:58:21 2022 -0800

    get release modules to work by removing package initialization from modules that shouldn't be there, by using Closure Compiler for externs reports, and adding Language APIs to the externs report
---
 .../compiler/utils/JSClosureCompilerWrapper.java   | 154 ++++++++++++++++++++-
 1 file changed, 149 insertions(+), 5 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java
index b93f276..f66acea 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java
@@ -22,6 +22,7 @@ package org.apache.royale.compiler.utils;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -29,6 +30,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.logging.Level;
 
+import com.google.common.io.Files;
 import com.google.javascript.jscomp.CheckLevel;
 import com.google.javascript.jscomp.CommandLineRunner;
 import com.google.javascript.jscomp.CompilationLevel;
@@ -36,6 +38,7 @@ import com.google.javascript.jscomp.Compiler;
 import com.google.javascript.jscomp.CompilerMapFetcher;
 import com.google.javascript.jscomp.CompilerOptions;
 import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
+import com.google.javascript.jscomp.CompilerOptions.PropertyCollapseLevel;
 import com.google.javascript.jscomp.DependencyOptions;
 import com.google.javascript.jscomp.DependencyOptions.DependencyMode;
 import com.google.javascript.jscomp.DiagnosticGroups;
@@ -51,10 +54,11 @@ import com.google.javascript.jscomp.WarningLevel;
 public class JSClosureCompilerWrapper
 {
 
-    public JSClosureCompilerWrapper(List<String> args) throws IOException
+    public JSClosureCompilerWrapper(List<String> args, boolean isModule) throws IOException
     {
         Compiler.setLoggingLevel(Level.INFO);
-
+        this.isModule = isModule;
+        
         compiler_ = new Compiler();
         jsSourceFiles_ = new ArrayList<SourceFile>();
         jsExternsFiles_ = new ArrayList<SourceFile>();
@@ -95,7 +99,8 @@ public class JSClosureCompilerWrapper
     private boolean sourceMap = false;
     private boolean verbose = false;
     private boolean preventRenameMxmlSymbolReferences = true;
-    
+    private boolean isModule = false;
+    private String moduleExterns;
     public String targetFilePath;
     
     public void addJSExternsFile(String fileName)
@@ -143,6 +148,8 @@ public class JSClosureCompilerWrapper
         extraSymbolNamesToExport = names;
     }
     
+    private File externExport;
+    
     public boolean compile()
     {
         if (verbose)
@@ -186,7 +193,54 @@ public class JSClosureCompilerWrapper
         try
         {
             FileWriter targetFile = new FileWriter(targetFilePath);
-            targetFile.write(compiler_.toSource());
+            String output = compiler_.toSource();
+            if (isModule && moduleExterns != null) 
+            {
+                List<String> fileLines = null;
+                try
+                {
+                    fileLines = Files.readLines(new File(moduleExterns), Charset.forName("utf8"));
+                }
+                catch(IOException e)
+                {
+    				// TODO Auto-generated catch block
+    				e.printStackTrace();
+                }
+                List<String> packages = new ArrayList<String>();
+                if (fileLines != null)
+                {
+                    for (String line : fileLines) 
+                    {
+                    	if (line.contains(" = {}")) 
+                    	{
+                    		packages.add(line.substring(0, line.length() - 6));
+                    	}
+                    }                	
+                }
+                for (String pkg : packages) 
+                {
+                	// module output mistakenly contains
+                	// org.apache.royale.core={};
+                	output = output.replace(pkg+"={};", "");
+                	int c = pkg.lastIndexOf(".");
+                	int c2 = pkg.indexOf(".");
+                	while (c > c2)
+                	{
+                		pkg = pkg.substring(0, c);
+                    	output = output.replace(pkg+"={};", "");
+                    	c = pkg.lastIndexOf(".");
+                	}
+                	if (c != -1)
+                	{
+                    	// module output mistakenly contains
+                    	// var org={apache:{}};
+                		String root = pkg.substring(0, c);
+                		String next = pkg.substring(c + 1);
+                		output = output.replace("var "+root+"={"+next+":{}};", "");
+                	}
+                }
+            }
+            targetFile.write(output);
             targetFile.close();
 
             if (sourceMap)
@@ -201,6 +255,82 @@ public class JSClosureCompilerWrapper
             System.out.println(error);
         }
         
+        if (externExport != null && result.externExport != null) {
+            try
+            {
+                FileWriter targetFile = new FileWriter(externExport.getAbsolutePath());
+                String report = result.externExport;
+				// Anything added here needs to be added to GoogDepsWriter.
+				// This exports it, but also needs to be in externs
+                report += "\n\n" +
+                		"/**\n" + 
+                		" * @constructor\n" + 
+                		" */\n" + 
+                		"org.apache.royale.utils.Language = function() {\n" + 
+                		"};\n" + 
+                		"/**\n" + 
+                		" * @param {Object} left\n" + 
+                		" * @param {Object} right\n" + 
+                		" * @param {boolean} coercion\n" + 
+                		" * @return {Object}\n" + 
+                		" */\n" + 
+                		"org.apache.royale.utils.Language.as = function(left, right, coercion) {\n" + 
+                		"};\n" +
+                		"/**\n" + 
+                		" * @param {number} value\n" + 
+                		" * @return {number}\n" + 
+                		" */\n" + 
+                		"org.apache.royale.utils.Language._int = function(value) {\n" + 
+                		"};\n" +
+                		"/**\n" + 
+                		" * @param {Object} value\n" + 
+                		" * @return {string}\n" + 
+                		" */\n" + 
+                		"org.apache.royale.utils.Language.string = function(value) {\n" + 
+                		"};\n" +
+                		"/**\n" + 
+                		" * @param {Object} left\n" + 
+                		" * @param {Object} right\n" + 
+                		" * @return {boolean}\n" + 
+                		" */\n" + 
+                		"org.apache.royale.utils.Language.is = function(left, right) {\n" + 
+                		"};\n" +
+                		"/**\n" + 
+                		" * @param {number} value\n" + 
+                		" * @return {number}\n" + 
+                		" */\n" + 
+                		"org.apache.royale.utils.Language.uint = function(value) {\n" + 
+                		"};\n" +
+                		"/**\n" + 
+                		" * @param {Function} fn\n" + 
+                		" * @param {Object} obj\n" + 
+                		" * @param {string} boundMethodName\n" + 
+                		" * @return {Function}\n" + 
+                		" */\n" + 
+                		"org.apache.royale.utils.Language.closure = function(fn, obj, boundMethodName) {\n" + 
+                		"};\n" +
+                		"/**\n" + 
+                		" * @param {Object} arr\n" + 
+                		" * @return {Object}\n" + 
+                		" */\n" + 
+                		"org.apache.royale.utils.Language.sort = function(arr, args) {\n" + 
+                		"};\n" +
+		        		"/**\n" + 
+		        		" * @param {Object} arr\n" + 
+		        		" * @param {Object} names\n" + 
+		        		" * @param {Object} opt\n" + 
+		        		" * @return {Object}\n" + 
+		        		" */\n" + 
+		        		"org.apache.royale.utils.Language.sortOn = function(arr, names, opt) {\n" + 
+		        		"};\n";
+                targetFile.write(report);
+                targetFile.close();
+            }        	
+            catch (IOException error)
+            {
+                System.out.println(error);
+            }
+        }
         if (variableMapOutputPath != null)
         {
         	File outputFile = new File(outputFolder, variableMapOutputPath);
@@ -314,6 +444,7 @@ public class JSClosureCompilerWrapper
     			String fileName = s.substring(EXTERNS.length());
     			addJSExternsFile(fileName);
     			removeArgs.add(s);
+    			moduleExterns = fileName;
     		}    			
     	}
     	if (varEntry != null)
@@ -392,7 +523,7 @@ public class JSClosureCompilerWrapper
     }
     
     @SuppressWarnings("deprecation")
-	public void setOptions(String sourceMapPath, boolean useStrictPublishing, boolean manageDependencies, String projectName)
+	public void setOptions(String sourceMapPath, boolean useStrictPublishing, boolean manageDependencies, String projectName, File externsReport)
     {
         if (useStrictPublishing)
         {
@@ -426,12 +557,20 @@ public class JSClosureCompilerWrapper
             options_.setInlineProperties(false);
             options_.setInlineVariables(true);
             options_.setSmartNameRemoval(true);
+            options_.setExtraSmartNameRemoval(true);
             options_.setRemoveDeadCode(true);
+            options_.setRewritePolyfills(true);
             options_.setExtractPrototypeMemberDeclarations(true);
             options_.setRemoveUnusedPrototypeProperties(true);
             options_.setRemoveUnusedPrototypePropertiesInExterns(false);
             options_.setRemoveUnusedClassProperties(true);
+            options_.setRemoveUnusedConstructorProperties(true);
             options_.setRemoveUnusedVariables(CompilerOptions.Reach.ALL);
+            if (isModule)
+            {
+            	options_.setRenamePrefix("A_A");
+            	options_.setCollapsePropertiesLevel(PropertyCollapseLevel.NONE);
+            }
             options_.setCollapseVariableDeclarations(true);
             options_.setCollapseAnonymousFunctions(true);
             options_.setAliasAllStrings(true);
@@ -444,6 +583,11 @@ public class JSClosureCompilerWrapper
             options_.addWarningsGuard(new ShowByPathWarningsGuard(
                     new String[] { "goog/", "externs/svg.js" },
                     ShowByPathWarningsGuard.ShowType.EXCLUDE));
+            if (externsReport != null) {
+            	externExport = externsReport;
+                options_.setExternExports(true);
+                options_.setExternExportsPath(externsReport.getAbsolutePath());            	
+            }
             
             ArrayList<String> entryPoints = new ArrayList<String>();
             if (manageDependencies)

[royale-compiler] 01/06: revert back to original passes

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch ReleaseModules
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 29eea23bc52d621c22c35c08b15b3c804c9e0f9e
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Jan 11 00:28:53 2022 -0800

    revert back to original passes
---
 .../javascript/jscomp/RoyaleClosurePassConfig.java | 33 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/compiler-jx/src/main/java/com/google/javascript/jscomp/RoyaleClosurePassConfig.java b/compiler-jx/src/main/java/com/google/javascript/jscomp/RoyaleClosurePassConfig.java
index fef8ed8..b07142b 100644
--- a/compiler-jx/src/main/java/com/google/javascript/jscomp/RoyaleClosurePassConfig.java
+++ b/compiler-jx/src/main/java/com/google/javascript/jscomp/RoyaleClosurePassConfig.java
@@ -1358,13 +1358,20 @@ public final class RoyaleClosurePassConfig extends PassConfig {
 		@Override
         protected HotSwapCompilerPass create(final AbstractCompiler compiler) {
           preprocessorSymbolTableFactory.maybeInitialize(compiler);
+          /*
           final ProcessClosurePrimitivesWithModuleSupport pass =
               new ProcessClosurePrimitivesWithModuleSupport(
                   compiler,
                   preprocessorSymbolTableFactory.getInstanceOrNull(),
                   options.brokenClosureRequiresLevel,
                   options.shouldPreservesGoogProvidesAndRequires());
-
+		  */
+          final ProcessClosurePrimitives pass =
+                  new ProcessClosurePrimitives(
+                      compiler,
+                      preprocessorSymbolTableFactory.getInstanceOrNull(),
+                      options.brokenClosureRequiresLevel,
+                      options.shouldPreservesGoogProvidesAndRequires());
           return new HotSwapCompilerPass() {
             @Override
             public void process(Node externs, Node root) {
@@ -2472,7 +2479,8 @@ public final class RoyaleClosurePassConfig extends PassConfig {
       new PassFactory(PassNames.COLLAPSE_PROPERTIES, true) {
         @Override
         protected CompilerPass create(AbstractCompiler compiler) {
-          return new CollapsePropertiesWithModuleSupport(compiler, options.getPropertyCollapseLevel(), sourceFileName, varRenameMapFile);
+          //return new CollapsePropertiesWithModuleSupport(compiler, options.getPropertyCollapseLevel(), sourceFileName, varRenameMapFile);
+          return new CollapseProperties(compiler, options.getPropertyCollapseLevel());
         }
 
         @Override
@@ -3099,6 +3107,7 @@ public final class RoyaleClosurePassConfig extends PassConfig {
           return new CompilerPass() {
             @Override
             public void process(Node externs, Node root) {
+              /*
               RenamePropertiesWithModuleSupport rprop =
                   new RenamePropertiesWithModuleSupport(
                       compiler,
@@ -3108,6 +3117,12 @@ public final class RoyaleClosurePassConfig extends PassConfig {
                       options.getPropertyReservedNamingNonFirstChars(),
                       options.nameGenerator,
                       null);
+              */
+              RenameProperties rprop = 
+            		  new RenameProperties(
+            				  compiler,
+            				  options.generatePseudoNames,
+                              options.nameGenerator);
               rprop.process(externs, root);
               compiler.setPropertyMap(rprop.getPropertyMap());
             }
@@ -3152,6 +3167,7 @@ public final class RoyaleClosurePassConfig extends PassConfig {
     }
     reservedNames.addAll(compiler.getExportedNames());
     reservedNames.addAll(ParserRunner.getReservedVars());
+    /*
     RenameVarsWithModuleSupport rn = new RenameVarsWithModuleSupport(
         compiler,
         options.renamePrefix,
@@ -3164,6 +3180,19 @@ public final class RoyaleClosurePassConfig extends PassConfig {
         reservedChars,
         reservedNames,
         options.nameGenerator);
+    */
+    RenameVars rn = new RenameVars(
+            compiler,
+            options.renamePrefix,
+            options.variableRenaming == VariableRenamingPolicy.LOCAL,
+            preserveAnonymousFunctionNames,
+            options.generatePseudoNames,
+            options.shadowVariables,
+            options.preferStableNames,
+            prevVariableMap,
+            reservedChars,
+            reservedNames,
+    		options.nameGenerator);
     rn.process(externs, root);
     return rn.getVariableMap();
   }

[royale-compiler] 03/06: get release modules to work by preventing rename of superClass_ in base.js, and by excluding compilation of files excluded from the module

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch ReleaseModules
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 5a60e41d795e003a4d781626f489f6d50ac881f6
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Jan 11 00:45:02 2022 -0800

    get release modules to work by preventing rename of superClass_ in base.js, and by excluding compilation of files excluded from the module
---
 .../codegen/mxml/royale/MXMLRoyalePublisher.java   | 52 +++++++++++++++++++++-
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
index ec52ced..2d6759c 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
@@ -391,6 +391,30 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSGoogPubli
             FileUtils.write(new File(new File(intermediateDir, "library/closure"),
                     closureSourceFile.getName()), closureSourceFile.getCode(), Charset.forName("utf8"));
         }
+        if ((googConfiguration.getExternsReport() != null) ||
+        		project.isModule(mainClassQName))
+        {
+        	File baseJS = new File(intermediateDir, "library/closure/goog/base.js");
+            String input = readCode(baseJS);
+            input = input.replaceAll("\\.superClass_", "[\"superClass_\"]");
+            FileUtils.write(baseJS, input);
+            int n = closureSourceFiles.size();
+            for (int i = 0; i < n; i++)
+            {
+            	SourceFile sf = closureSourceFiles.get(i);
+            	String name = sf.getName();
+            	if (name.contains("base.js"))
+            	{
+                    //String relative = new File(intermediateDir, "closure").toURI().relativize(baseJS.toURI()).getPath();
+                    //String code = FileUtils.readFileToString(baseJS, "UTF-8");
+                    SourceFile sourceFile = new JarSourceFile(sf.getName(), input, false);
+            		//SourceFile sourceFile = SourceFile.fromFile(baseJS.getAbsolutePath());
+                    closureSourceFiles.set(i, sourceFile);
+                    break;
+            	}
+            }
+        }
+        
         List<String> closureEntryPoints = new ArrayList<String>();
         closureEntryPoints.add("goog.events.EventTarget");
         closureEntryPoints.add("goog.html.sanitizer.HtmlSanitizer");
@@ -404,7 +428,7 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSGoogPubli
         JSClosureCompilerWrapper compilerWrapper = null;
         if (configuration.release())
         {
-            compilerWrapper = new JSClosureCompilerWrapper(googConfiguration.getJSCompilerOptions());
+            compilerWrapper = new JSClosureCompilerWrapper(googConfiguration.getJSCompilerOptions(), project.isModule(mainClassQName));
             compilerWrapper.setPropertyNamesToKeep(closurePropertyNamesToKeep);
             if (closureSymbolNamesToExport == null) {
                 closureSymbolNamesToExport = new HashSet<String>();
@@ -497,8 +521,32 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSGoogPubli
         }
         if (compilerWrapper != null)
         {
+        	Set<String> externs = googConfiguration.getExterns();
             for (String file : fileList)
             {
+            	if (externs.size() > 0)
+            	{
+            		if (gdw.providedMap.containsKey(file))
+        			{
+            			String provided = gdw.providedMap.get(file);
+            			if (externs.contains(provided))
+            			{
+                            if (googConfiguration.isVerbose())
+                            {            
+                                System.out.println("skipping extern source file: " + file);
+                            }
+            				continue;
+            			}
+        			}
+            		if (file.endsWith("Language.js"))
+            		{
+                        if (googConfiguration.isVerbose())
+                        {            
+                            System.out.println("skipping extern source file: " + file);
+                        }
+        				continue;            			
+            		}
+            	}
                 compilerWrapper.addJSSourceFile(file);
                 if (googConfiguration.isVerbose())
                 {            
@@ -594,7 +642,7 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSGoogPubli
         if (compilerWrapper != null) {
             boolean ok = true;
             final File projectReleaseMainFile = new File(releaseDir, outputFileName);
-            compilerWrapper.setOptions(projectReleaseMainFile.getCanonicalPath(), useStrictPublishing, !googConfiguration.getRemoveCirculars(), projectName);
+            compilerWrapper.setOptions(projectReleaseMainFile.getCanonicalPath(), useStrictPublishing, !googConfiguration.getRemoveCirculars(), projectName, googConfiguration.getExternsReport());
             compilerWrapper.targetFilePath = projectReleaseMainFile.getCanonicalPath();
             compilerWrapper.setSourceMap(googConfiguration.getSourceMap());
             compilerWrapper.setVerbose(googConfiguration.isVerbose());

[royale-compiler] 02/06: move externs reporting to Closure Compiler. It knows how to produce a much better set of externs

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch ReleaseModules
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit d27c834edaabed222bc9c7030a0818ecd13795a0
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Jan 11 00:40:53 2022 -0800

    move externs reporting to Closure Compiler.  It knows how to produce a much better set of externs
---
 .../main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
index 69b3b98..b856a49 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
@@ -426,9 +426,9 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
                         ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep);
                         ClosureUtils.collectSymbolNamesToExport(cu, project, closureSymbolNamesToExport);
 	                }
-	                File externsReportFile = googConfiguration.getExternsReport();
-	                if (externsReportFile != null)
-	                	generateExternsReport(externsReportFile, reachableCompilationUnits, problems);
+//	                File externsReportFile = googConfiguration.getExternsReport();
+//	                if (externsReportFile != null)
+//	                	generateExternsReport(externsReportFile, reachableCompilationUnits, problems);
                 }
                 
                 if (!config.getCreateTargetWithErrors())