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

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


The following commit(s) were added to refs/heads/develop by this push:
     new eed5882  add -warn-public-vars option to emit warning on use of public 
vars since they do not work well when minified and used from MXML.  There is an 
asdoc option @royalesuppresspublicvarwarning that can be used on a declaration 
or entire class to suppress the warning
eed5882 is described below

commit eed5882ba935870a98ba4fe8cbf499e5d8344f60
Author: Alex Harui <[email protected]>
AuthorDate: Mon Feb 19 18:32:06 2018 -0800

    add -warn-public-vars option to emit warning on use of public vars since 
they do not work well when minified and used from MXML.  There is an asdoc 
option @royalesuppresspublicvarwarning that can be used on a declaration or 
entire class to suppress the warning
---
 .../compiler/problems/PublicVarWarningProblem.java | 44 ++++++++++++++++++++++
 .../apache/royale/compiler/clients/MXMLJSC.java    |  1 +
 .../codegen/js/royale/JSRoyaleDocEmitter.java      | 42 +++++++++++++++++++++
 .../codegen/js/royale/JSRoyaleEmitterTokens.java   |  1 +
 .../driver/js/goog/JSGoogCompcConfiguration.java   | 19 +++++++++-
 .../driver/js/goog/JSGoogConfiguration.java        | 19 ++++++++++
 6 files changed, 125 insertions(+), 1 deletion(-)

diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/problems/PublicVarWarningProblem.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/problems/PublicVarWarningProblem.java
new file mode 100644
index 0000000..02fddc8
--- /dev/null
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/problems/PublicVarWarningProblem.java
@@ -0,0 +1,44 @@
+/*
+ *
+ *  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.problems;
+
+import org.apache.royale.compiler.common.ISourceLocation;
+import org.apache.royale.compiler.problems.annotations.DefaultSeverity;
+
+/**
+ *  Public vars don't work well in JS minified output.  The minifier
+ *  creates a "name" reference then gives the var a new minified name.
+ *  If the var is not read-only, the write to the var means the
+ *  reference is obsolete.  Also, MXML and States access attributes
+ *  by name which also breaks the reference.  Use getter/setters instead.
+ */
+@DefaultSeverity(CompilerProblemSeverity.WARNING)
+public class PublicVarWarningProblem extends CompilerProblem
+{
+    public static final String DESCRIPTION =
+        "public var may not work in minified JS output.  Use getter/setter 
instead.";
+    
+    public static final int warningCode = 5044;
+    
+    public PublicVarWarningProblem(ISourceLocation site)
+    {
+        super(site);
+    }
+}
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 d527469..c2f38e2 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
@@ -445,6 +445,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, 
ProblemQueryProvider,
                          arg.startsWith("-compiler.js-define") ||
                          arg.startsWith("-js-output") ||
                          arg.startsWith("-js-load-config") ||
+                         arg.startsWith("-warn-public-vars") ||
                          arg.startsWith("-source-map")))
                        list.add(arg);                                          
        }
diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleDocEmitter.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleDocEmitter.java
index 2dd2f74..a4f8d05 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleDocEmitter.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleDocEmitter.java
@@ -41,8 +41,11 @@ import 
org.apache.royale.compiler.internal.codegen.js.goog.JSGoogDocEmitterToken
 import org.apache.royale.compiler.internal.codegen.js.jx.BindableEmitter;
 import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
 import org.apache.royale.compiler.internal.scopes.ASScope;
+import org.apache.royale.compiler.problems.PublicVarWarningProblem;
 import org.apache.royale.compiler.projects.ICompilerProject;
+import org.apache.royale.compiler.tree.ASTNodeID;
 import org.apache.royale.compiler.tree.as.IASNode;
+import org.apache.royale.compiler.tree.as.IClassNode;
 import org.apache.royale.compiler.tree.as.IDefinitionNode;
 import org.apache.royale.compiler.tree.as.IExpressionNode;
 import org.apache.royale.compiler.tree.as.IFunctionNode;
@@ -422,6 +425,13 @@ public class JSRoyaleDocEmitter extends JSGoogDocEmitter
         }
         else
         {
+               RoyaleJSProject fjp =  (RoyaleJSProject)project;
+            boolean warnPublicVars = fjp.config != null && 
fjp.config.getWarnPublicVars();
+            if (warnPublicVars && !node.isConst() && !def.isBindable())
+            {
+                if (!suppressedWarning(node, fjp))
+                       fjp.getProblems().add(new 
PublicVarWarningProblem(node));
+            }
             emitPublic(node);
         }
 
@@ -443,5 +453,37 @@ public class JSRoyaleDocEmitter extends JSGoogDocEmitter
        if (emitExports)
                super.emitPublic(node);
     }
+    
+    private boolean suppressedWarning(IVariableNode node, RoyaleJSProject fjp)
+    {
+       boolean suppressed = false;
+        ASDocComment asDoc = (ASDocComment) node.getASDocComment();
+        boolean keepASDoc = fjp.config != null && fjp.config.getKeepASDoc();
+        String suppressToken = 
JSRoyaleEmitterTokens.SUPPRESS_PUBLIC_VAR_WARNING
+        .getToken();
+        if (asDoc != null && keepASDoc)
+        {
+            String docText = asDoc.commentNoEnd();
+            if (docText.contains(suppressToken))
+                return true;
+        }
+       IASNode classNode = node.getParent().getParent();
+       if (classNode == null)
+               return false;
+       if (classNode.getNodeID() == ASTNodeID.ClassID)
+       {
+               asDoc = (ASDocComment) 
((IClassNode)classNode).getASDocComment();
+            if (asDoc != null && keepASDoc)
+            {
+                String docText = asDoc.commentNoEnd();
+                if (docText.contains(suppressToken))
+                    return true;
+            }
+            IClassDefinition cdef = ((IClassNode)classNode).getDefinition();
+            if (cdef.isBindable())
+               return true;
+       }
+       return false;
+    }
 
 }
diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitterTokens.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitterTokens.java
index 5d8a091..f6235d3 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitterTokens.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitterTokens.java
@@ -45,6 +45,7 @@ public enum JSRoyaleEmitterTokens implements IEmitterTokens
     IGNORE_COERCION("@royaleignorecoercion"),
     IGNORE_IMPORT("@royaleignoreimport"),
     IGNORE_STRING_COERCION("@royalenoimplicitstringconversion"),
+    SUPPRESS_PUBLIC_VAR_WARNING("@royalesuppresspublicvarwarning"),
     PREINCREMENT("preincrement"),
     PREDECREMENT("predecrement"),
     POSTINCREMENT("postincrement"),
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 d776b8d..c5581b0 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
@@ -422,6 +422,23 @@ public class JSGoogCompcConfiguration extends 
JSConfiguration
        exportPublicSymbols = value;
     }
 
-    
+    //
+    // 'warn-public-vars'
+    //
+
+    private boolean warnPublicVars = true;
+
+    public boolean getWarnPublicVars()
+    {
+        return warnPublicVars;
+    }
+
+    @Config
+    @Mapping("warn-public-vars")
+    public void setWarnPublicVars(ConfigurationValue cv, boolean value)
+            throws ConfigurationException
+    {
+       warnPublicVars = value;
+    }    
 
 }
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 9239f96..01cd133 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
@@ -422,6 +422,25 @@ public class JSGoogConfiguration extends JSConfiguration
     }
 
     
+    //
+    // 'warn-public-vars'
+    //
+
+    private boolean warnPublicVars = true;
+
+    public boolean getWarnPublicVars()
+    {
+        return warnPublicVars;
+    }
+
+    @Config
+    @Mapping("warn-public-vars")
+    public void setWarnPublicVars(ConfigurationValue cv, boolean value)
+            throws ConfigurationException
+    {
+       warnPublicVars = value;
+    }
+
     
 
 }

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to