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 2020/03/31 17:47:58 UTC

[royale-compiler] 01/05: Prevent renaming of public variables (static or non-static)

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 21d8cae1a1bf444390ab66435b46f0f9b4c6800c
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Mar 30 18:02:02 2020 -0700

    Prevent renaming of public variables (static or non-static)
---
 .../javascript/jscomp/RoyaleClosurePassConfig.java | 53 ++++++++++++-
 .../apache/royale/compiler/clients/MXMLJSC.java    | 10 ++-
 .../royale/compiler/clients/MXMLJSCNative.java     | 11 ++-
 .../royale/compiler/clients/MXMLJSCNode.java       | 10 ++-
 .../royale/compiler/clients/MXMLJSCRoyale.java     | 11 ++-
 .../compiler/clients/MXMLJSCRoyaleCordova.java     | 11 ++-
 .../compiler/codegen/js/goog/IJSGoogPublisher.java | 33 +++++++++
 .../codegen/mxml/royale/MXMLRoyalePublisher.java   | 12 ++-
 .../driver/js/goog/JSGoogCompcConfiguration.java   |  2 +-
 .../driver/js/goog/JSGoogConfiguration.java        |  2 +-
 .../apache/royale/compiler/utils/ClosureUtils.java | 86 ++++++++++++++++++++++
 .../compiler/utils/JSClosureCompilerWrapper.java   |  9 ++-
 12 files changed, 227 insertions(+), 23 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 84fae02..449918c 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
@@ -61,7 +61,10 @@ import com.google.javascript.jscomp.lint.CheckUselessBlocks;
 import com.google.javascript.jscomp.parsing.ParserRunner;
 import com.google.javascript.jscomp.parsing.parser.FeatureSet;
 import com.google.javascript.rhino.IR;
+import com.google.javascript.rhino.JSDocInfo;
+import com.google.javascript.rhino.JSDocInfoBuilder;
 import com.google.javascript.rhino.Node;
+import com.google.javascript.rhino.Token;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -130,8 +133,10 @@ public final class RoyaleClosurePassConfig extends PassConfig {
 
   /** file of already renamed vars */
   private File varRenameMapFile;
+
+  private Set<String> propertyNamesToKeep;
   
-  public RoyaleClosurePassConfig(CompilerOptions options, String sourceFileName, File varRenameMapFile) {
+  public RoyaleClosurePassConfig(CompilerOptions options, String sourceFileName, File varRenameMapFile, Set<String> propertyNamesToKeep) {
     super(options);
 
     // The current approach to protecting "hidden" side-effects is to
@@ -141,6 +146,7 @@ public final class RoyaleClosurePassConfig extends PassConfig {
     preprocessorSymbolTableFactory = new PreprocessorSymbolTable.CachedInstanceFactory();
     this.varRenameMapFile = varRenameMapFile;
     this.sourceFileName = sourceFileName;
+    this.propertyNamesToKeep = propertyNamesToKeep;
   }
 
   GlobalNamespace getGlobalNamespace() {
@@ -335,6 +341,10 @@ public final class RoyaleClosurePassConfig extends PassConfig {
       checks.add(angularPass);
     }
 
+    if (propertyNamesToKeep != null && propertyNamesToKeep.size() > 0) {
+      checks.add(keepPropertyNamesPass);
+    }
+
     if (!options.generateExportsAfterTypeChecking && options.generateExports) {
       checks.add(generateExports);
     }
@@ -1255,6 +1265,47 @@ public final class RoyaleClosurePassConfig extends PassConfig {
         }
       };
 
+    private final PassFactory keepPropertyNamesPass = 
+        new PassFactory("keep-property-names", true) {
+          @Override
+          protected CompilerPass create(final AbstractCompiler compiler) {
+            return new CompilerPass() {
+              @Override
+              public void process(Node externs, Node root) {
+
+                Node propsObj = new Node(Token.OBJECTLIT);
+                for(String nameToKeep : propertyNamesToKeep)
+                {
+                  Node nameStringKey = IR.stringKey(nameToKeep);
+                  JSDocInfoBuilder builder = new JSDocInfoBuilder(true);
+                  builder.recordExport();
+                  JSDocInfo jsDocInfo = builder.build();
+                  nameStringKey.setJSDocInfo(jsDocInfo);
+
+                  Node propertyDescriptor = new Node(Token.OBJECTLIT);
+                  propertyDescriptor.addChildToBack(IR.propdef(IR.stringKey("get"), NodeUtil.emptyFunction()));
+
+                  Node prop = IR.propdef(nameStringKey, propertyDescriptor);
+                  propsObj.addChildToBack(prop);
+                }
+
+                Node definePropertiesTarget = NodeUtil.newQName(compiler, "Object.defineProperties");
+                Node definePropertiesCall = IR.call(definePropertiesTarget, IR.objectlit(), propsObj);
+                Node expression = IR.exprResult(definePropertiesCall);
+                
+                Node scriptNode = compiler.getScriptNode(sourceFileName);
+                scriptNode.addChildToBack(expression);
+                compiler.reportChangeToEnclosingScope(expression);
+              }
+            };
+          }
+    
+          @Override
+          protected FeatureSet featureSet() {
+            return ES_NEXT;
+          }
+        };
+
   /** Raw exports processing pass. */
   private final PassFactory gatherRawExports =
       new PassFactory(PassNames.GATHER_RAW_EXPORTS, true) {
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
index 5bed5df..748c169 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
@@ -35,8 +35,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter;
 import org.apache.royale.compiler.clients.problems.ProblemQuery;
 import org.apache.royale.compiler.clients.problems.ProblemQueryProvider;
 import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
-import org.apache.royale.compiler.codegen.js.IJSPublisher;
 import org.apache.royale.compiler.codegen.js.IJSWriter;
+import org.apache.royale.compiler.codegen.js.goog.IJSGoogPublisher;
 import org.apache.royale.compiler.common.VersionInfo;
 import org.apache.royale.compiler.config.CommandLineConfigurator;
 import org.apache.royale.compiler.config.CompilerDiagnosticsConstants;
@@ -75,6 +75,7 @@ import org.apache.royale.compiler.targets.ITarget;
 import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
 import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.compiler.utils.ClosureUtils;
 import org.apache.royale.swf.ISWF;
 import org.apache.royale.swf.SWF;
 import org.apache.royale.swf.types.RGB;
@@ -272,7 +273,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     protected ITarget target;
     protected ITargetSettings targetSettings;
     protected IJSApplication jsTarget;
-    private IJSPublisher jsPublisher;
+    private IJSGoogPublisher jsPublisher;
     protected MXMLC mxmlc;
     protected JSCompilerEntryPoint lastCompiler;
     public boolean noLink;
@@ -532,7 +533,8 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
                         return false;
                 }
 
-                jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+                Set<String> closurePropNamesToKeep = new HashSet<String>();
+                jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher(
                         project, errors, config);
 
                 File outputFolder = jsPublisher.getOutputFolder();
@@ -617,11 +619,13 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
 	                    		outputClassFile.setLastModified(fileDate);
 	                    	}
 	                    }
+                        ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep);
 	                }
                 }
                 
                 if (jsPublisher != null)
                 {
+                    jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep);
                     compilationSuccess = jsPublisher.publish(problems);
                 }
                 else
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
index 1c4474f..9b54b1e 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
@@ -36,8 +37,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter;
 import org.apache.royale.compiler.clients.problems.ProblemQuery;
 import org.apache.royale.compiler.clients.problems.ProblemQueryProvider;
 import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
-import org.apache.royale.compiler.codegen.js.IJSPublisher;
 import org.apache.royale.compiler.codegen.js.IJSWriter;
+import org.apache.royale.compiler.codegen.js.goog.IJSGoogPublisher;
 import org.apache.royale.compiler.config.Configuration;
 import org.apache.royale.compiler.config.ConfigurationBuffer;
 import org.apache.royale.compiler.config.Configurator;
@@ -72,6 +73,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
 import org.apache.royale.compiler.units.ICompilationUnit;
 import org.apache.royale.compiler.units.ICompilationUnit.UnitType;
+import org.apache.royale.compiler.utils.ClosureUtils;
 import org.apache.flex.tools.FlexTool;
 import org.apache.royale.utils.ArgumentUtil;
 import org.apache.royale.utils.FilenameNormalization;
@@ -169,7 +171,7 @@ public class MXMLJSCNative implements JSCompilerEntryPoint, ProblemQueryProvider
     protected ITarget target;
     protected ITargetSettings targetSettings;
     protected IJSApplication jsTarget;
-    private IJSPublisher jsPublisher;
+    private IJSGoogPublisher jsPublisher;
     
     public MXMLJSCNative()
     {
@@ -315,7 +317,8 @@ public class MXMLJSCNative implements JSCompilerEntryPoint, ProblemQueryProvider
                         return false;
                 }
 
-                jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+                Set<String> closurePropNamesToKeep = new HashSet<String>();
+                jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher(
                         project, errors, config);
 
                 File outputFolder = jsPublisher.getOutputFolder();
@@ -381,11 +384,13 @@ public class MXMLJSCNative implements JSCompilerEntryPoint, ProblemQueryProvider
                             }
 	                        writer.close();
 	                    }
+                        ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep);
 	                }
                 }
                 
                 if (jsPublisher != null)
                 {
+                    jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep);
                     compilationSuccess = jsPublisher.publish(problems);
                 }
                 else
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
index bb83228..70c1c24 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
@@ -36,8 +37,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter;
 import org.apache.royale.compiler.clients.problems.ProblemQuery;
 import org.apache.royale.compiler.clients.problems.ProblemQueryProvider;
 import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
-import org.apache.royale.compiler.codegen.js.IJSPublisher;
 import org.apache.royale.compiler.codegen.js.IJSWriter;
+import org.apache.royale.compiler.codegen.js.goog.IJSGoogPublisher;
 import org.apache.royale.compiler.config.Configuration;
 import org.apache.royale.compiler.config.ConfigurationBuffer;
 import org.apache.royale.compiler.config.Configurator;
@@ -72,6 +73,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
 import org.apache.royale.compiler.units.ICompilationUnit;
 import org.apache.royale.compiler.units.ICompilationUnit.UnitType;
+import org.apache.royale.compiler.utils.ClosureUtils;
 import org.apache.flex.tools.FlexTool;
 import org.apache.royale.utils.ArgumentUtil;
 import org.apache.royale.utils.FilenameNormalization;
@@ -168,7 +170,7 @@ public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider,
     protected ITarget target;
     protected ITargetSettings targetSettings;
     protected IJSApplication jsTarget;
-    private IJSPublisher jsPublisher;
+    private IJSGoogPublisher jsPublisher;
 
     public MXMLJSCNode()
     {
@@ -317,7 +319,8 @@ public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider,
                         return false;
                 }
 
-                jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+                Set<String> closurePropNamesToKeep = new HashSet<String>();
+                jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher(
                         project, errors, config);
 
                 File outputFolder = jsPublisher.getOutputFolder();
@@ -383,6 +386,7 @@ public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider,
                             }
 	                        writer.close();
 	                    }
+                        ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep);
 	                }
                 }
                 
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 1236ef2..fe73f30 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
@@ -38,8 +38,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter;
 import org.apache.royale.compiler.clients.problems.ProblemQuery;
 import org.apache.royale.compiler.clients.problems.ProblemQueryProvider;
 import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
-import org.apache.royale.compiler.codegen.js.IJSPublisher;
 import org.apache.royale.compiler.codegen.js.IJSWriter;
+import org.apache.royale.compiler.codegen.js.goog.IJSGoogPublisher;
 import org.apache.royale.compiler.config.Configuration;
 import org.apache.royale.compiler.config.ConfigurationBuffer;
 import org.apache.royale.compiler.config.Configurator;
@@ -86,6 +86,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
 import org.apache.royale.compiler.units.ICompilationUnit;
 import org.apache.royale.compiler.units.ICompilationUnit.UnitType;
+import org.apache.royale.compiler.utils.ClosureUtils;
 import org.apache.flex.tools.FlexTool;
 import org.apache.royale.swc.ISWC;
 import org.apache.royale.swc.ISWCFileEntry;
@@ -188,7 +189,7 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
     protected ITarget target;
     protected ITargetSettings targetSettings;
     protected IJSApplication jsTarget;
-    private IJSPublisher jsPublisher;
+    private IJSGoogPublisher jsPublisher;
     
     public MXMLJSCRoyale()
     {
@@ -337,7 +338,8 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
                         return false;
                 }
 
-                jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+                Set<String> closurePropNamesToKeep = new HashSet<String>();
+                jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher(
                         project, errors, config);
 
                 File outputFolder = jsPublisher.getOutputFolder();
@@ -414,6 +416,7 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
                             }
 	                        writer.close();
 	                    }
+                        ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep);
 	                }
 	                File externsReportFile = googConfiguration.getExternsReport();
 	                if (externsReportFile != null)
@@ -431,6 +434,7 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
                 
                 if (jsPublisher != null)
                 {
+                    jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep);
                     compilationSuccess = jsPublisher.publish(problems);
                 }
                 else
@@ -817,7 +821,6 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
-
 	}
 	
 	/**
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
index 378339c..80bca1a 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
@@ -36,8 +37,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter;
 import org.apache.royale.compiler.clients.problems.ProblemQuery;
 import org.apache.royale.compiler.clients.problems.ProblemQueryProvider;
 import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
-import org.apache.royale.compiler.codegen.js.IJSPublisher;
 import org.apache.royale.compiler.codegen.js.IJSWriter;
+import org.apache.royale.compiler.codegen.js.goog.IJSGoogPublisher;
 import org.apache.royale.compiler.config.Configuration;
 import org.apache.royale.compiler.config.ConfigurationBuffer;
 import org.apache.royale.compiler.config.Configurator;
@@ -72,6 +73,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
 import org.apache.royale.compiler.units.ICompilationUnit;
 import org.apache.royale.compiler.units.ICompilationUnit.UnitType;
+import org.apache.royale.compiler.utils.ClosureUtils;
 import org.apache.flex.tools.FlexTool;
 import org.apache.royale.utils.ArgumentUtil;
 import org.apache.royale.utils.FilenameNormalization;
@@ -171,7 +173,7 @@ public class MXMLJSCRoyaleCordova implements JSCompilerEntryPoint, ProblemQueryP
     protected ITarget target;
     protected ITargetSettings targetSettings;
     protected IJSApplication jsTarget;
-    private IJSPublisher jsPublisher;
+    private IJSGoogPublisher jsPublisher;
     
     public MXMLJSCRoyaleCordova()
     {
@@ -320,7 +322,8 @@ public class MXMLJSCRoyaleCordova implements JSCompilerEntryPoint, ProblemQueryP
                         return false;
                 }
 
-                jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+                Set<String> closurePropNamesToKeep = new HashSet<String>();
+                jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher(
                         project, errors, config);
 
                 File outputFolder = jsPublisher.getOutputFolder();
@@ -386,11 +389,13 @@ public class MXMLJSCRoyaleCordova implements JSCompilerEntryPoint, ProblemQueryP
                             }
 	                        writer.close();
 	                    }
+                        ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep);
 	                }
                 }
                 
                 if (jsPublisher != null)
                 {
+                    jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep);
                     compilationSuccess = jsPublisher.publish(problems);
                 }
                 else
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/goog/IJSGoogPublisher.java b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/goog/IJSGoogPublisher.java
new file mode 100644
index 0000000..eaa3bad
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/goog/IJSGoogPublisher.java
@@ -0,0 +1,33 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.royale.compiler.codegen.js.goog;
+
+import java.util.Set;
+
+import org.apache.royale.compiler.codegen.js.IJSPublisher;
+
+/**
+ * The {@link IJSGoogPublisher} interface allows the abstraction of project output
+ * generation.
+ */
+public interface IJSGoogPublisher extends IJSPublisher
+{
+	void setClosurePropertyNamesToKeep(Set<String> propertyNames);
+}
\ No newline at end of file
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 77abfad..d823a33 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
@@ -28,7 +28,7 @@ import org.apache.commons.io.filefilter.FileFileFilter;
 import org.apache.commons.io.filefilter.FileFilterUtils;
 import org.apache.commons.io.filefilter.IOFileFilter;
 import org.apache.royale.compiler.clients.problems.ProblemQuery;
-import org.apache.royale.compiler.codegen.js.IJSPublisher;
+import org.apache.royale.compiler.codegen.js.goog.IJSGoogPublisher;
 import org.apache.royale.compiler.config.Configuration;
 import org.apache.royale.compiler.css.ICSSPropertyValue;
 import org.apache.royale.compiler.definitions.IClassDefinition;
@@ -40,7 +40,6 @@ import org.apache.royale.compiler.internal.codegen.js.goog.JarSourceFile;
 import org.apache.royale.compiler.internal.css.CSSArrayPropertyValue;
 import org.apache.royale.compiler.internal.css.CSSFontFace;
 import org.apache.royale.compiler.internal.css.CSSFunctionCallPropertyValue;
-import org.apache.royale.compiler.internal.definitions.ClassDefinition;
 import org.apache.royale.compiler.internal.driver.js.royale.JSCSSCompilationSession;
 import org.apache.royale.compiler.internal.driver.js.goog.JSGoogConfiguration;
 import org.apache.royale.compiler.internal.graph.GoogDepsWriter;
@@ -58,7 +57,7 @@ import java.net.URLDecoder;
 import java.nio.charset.Charset;
 import java.util.*;
 
-public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher
+public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSGoogPublisher
 {
 
     public static final String ROYALE_OUTPUT_DIR_NAME = "bin";
@@ -103,6 +102,7 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher
     private String moduleOutput;
     private boolean useStrictPublishing;
     private List<String> additionalHTML = new ArrayList<String>();
+    private Set<String> closurePropertyNamesToKeep;
 
     private GoogDepsWriter getGoogDepsWriter(File intermediateDir, 
     										String mainClassQName, 
@@ -183,6 +183,11 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher
         return outputFolder;
     }
 
+    public void setClosurePropertyNamesToKeep(Set<String> propertyNames)
+    {
+        closurePropertyNamesToKeep = propertyNames;
+    }
+
     @Override
     public boolean publish(ProblemQuery problems) throws IOException
     {
@@ -381,6 +386,7 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher
         if (configuration.release())
         {
             compilerWrapper = new JSClosureCompilerWrapper(googConfiguration.getJSCompilerOptions());
+            compilerWrapper.setPropertyNamesToKeep(closurePropertyNamesToKeep);
         }
 
         if (compilerWrapper != null)
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogCompcConfiguration.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogCompcConfiguration.java
index 2fa9464..a63a741 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogCompcConfiguration.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogCompcConfiguration.java
@@ -446,7 +446,7 @@ public class JSGoogCompcConfiguration extends JSConfiguration
     // 'warn-public-vars'
     //
 
-    private boolean warnPublicVars = true;
+    private boolean warnPublicVars = false;
 
     public boolean getWarnPublicVars()
     {
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 d4e5328..9942bd0 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
@@ -451,7 +451,7 @@ public class JSGoogConfiguration extends JSConfiguration
     // 'warn-public-vars'
     //
 
-    private boolean warnPublicVars = true;
+    private boolean warnPublicVars = false;
 
     public boolean getWarnPublicVars()
     {
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ClosureUtils.java b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ClosureUtils.java
new file mode 100644
index 0000000..785385e
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ClosureUtils.java
@@ -0,0 +1,86 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.royale.compiler.utils;
+
+import java.util.Set;
+
+import org.apache.royale.compiler.definitions.IDefinition;
+import org.apache.royale.compiler.definitions.IFunctionDefinition;
+import org.apache.royale.compiler.definitions.ITypeDefinition;
+import org.apache.royale.compiler.definitions.IVariableDefinition;
+import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
+import org.apache.royale.compiler.internal.scopes.ASProjectScope.DefinitionPromise;
+import org.apache.royale.compiler.units.ICompilationUnit;
+
+public class ClosureUtils
+{
+	public static void collectPropertyNamesToKeep(ICompilationUnit cu, RoyaleJSProject project, Set<String> result)
+    {
+        if (project.isExternalLinkage(cu))
+        {
+            return;
+        }
+		boolean renamePublic = false;
+		boolean renameProtected = true;
+        for (IDefinition def : cu.getDefinitionPromises())
+        {
+            if(def instanceof DefinitionPromise)
+            {
+                def = ((DefinitionPromise) def).getActualDefinition();
+            }
+            if (def instanceof ITypeDefinition)
+            {
+                if (def.isImplicit() || def.isNative())
+                {
+                    continue;
+                }
+                ITypeDefinition typeDef = (ITypeDefinition) def;
+                for (IDefinition localDef : typeDef.getContainedScope().getAllLocalDefinitions())
+                {
+                    if (localDef.isImplicit())
+                    {
+                        continue;
+                    }
+                    if (!localDef.isPublic() && !localDef.isProtected())
+                    {
+                        continue;
+                    }
+                    if (localDef.isProtected() && renameProtected)
+                    {
+                        continue;
+                    }
+                    if (localDef.isPublic() && renamePublic)
+                    {
+                        continue;
+                    }
+                    if (!(localDef instanceof IVariableDefinition))
+                    {
+                        continue;
+                    }
+                    if (localDef instanceof IFunctionDefinition)
+                    {
+                        continue;
+                    }
+                    result.add(localDef.getBaseName());
+                }
+            }
+        }
+    } 
+}
\ No newline at end of file
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 ae3d614..0364d35 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
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 import java.util.logging.Level;
 
 import com.google.javascript.jscomp.CheckLevel;
@@ -91,6 +92,7 @@ public class JSClosureCompilerWrapper
     private boolean skipTypeInference;
     private boolean sourceMap = false;
     private boolean verbose = false;
+    private Set<String> propertyNamesToKeep;
     
     public String targetFilePath;
     
@@ -123,6 +125,11 @@ public class JSClosureCompilerWrapper
     {
         verbose = enabled;
     }
+
+    public void setPropertyNamesToKeep(Set<String> propertyNames)
+    {
+        propertyNamesToKeep = propertyNames;
+    }
     
     public boolean compile()
     {
@@ -160,7 +167,7 @@ public class JSClosureCompilerWrapper
 
         compiler_.setPassConfig(new RoyaleClosurePassConfig(options_, 
         		jsSourceFiles_.get(jsSourceFiles_.size() - 1).getName(), 
-        		variableMapInputPath == null ? null : new File(outputFolder, variableMapInputPath)));
+        		variableMapInputPath == null ? null : new File(outputFolder, variableMapInputPath), propertyNamesToKeep));
         Result result = compiler_.compile(jsExternsFiles_, jsSourceFiles_, options_);
         
         try