Repository: flex-falcon
Updated Branches:
  refs/heads/initializers c17bdc9a5 -> b805d6d99


make default initialisers configurable


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

Branch: refs/heads/initializers
Commit: 62d53ed404bfa1cd2c3f75ce2463c0f01e3c7afe
Parents: c17bdc9
Author: Justin Mclean <jmcl...@apache.org>
Authored: Fri Jun 16 12:49:57 2017 +1000
Committer: Justin Mclean <jmcl...@apache.org>
Committed: Fri Jun 16 12:49:57 2017 +1000

----------------------------------------------------------------------
 .../codegen/js/jx/VarDeclarationEmitter.java    | 57 ++++++++++----------
 .../flex/compiler/config/Configuration.java     | 23 ++++++++
 .../apache/flex/compiler/messages_en.properties |  1 +
 .../org/apache/flex/compiler/ant/COMPCTask.java |  1 +
 .../org/apache/flex/compiler/ant/MXMLCTask.java |  1 +
 5 files changed, 54 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/62d53ed4/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
 
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
index 67ae28f..a4c8e22 100644
--- 
a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
+++ 
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
@@ -19,6 +19,7 @@
 
 package org.apache.flex.compiler.internal.codegen.js.jx;
 
+import org.apache.flex.compiler.clients.JSConfiguration;
 import org.apache.flex.compiler.codegen.ISubEmitter;
 import org.apache.flex.compiler.codegen.js.IJSEmitter;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
@@ -28,6 +29,7 @@ import 
org.apache.flex.compiler.definitions.metadata.IMetaTagAttribute;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
 import org.apache.flex.compiler.internal.tree.as.DynamicAccessNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
@@ -42,10 +44,14 @@ import org.apache.flex.compiler.tree.as.IVariableNode;
 public class VarDeclarationEmitter extends JSSubEmitter implements
         ISubEmitter<IVariableNode>
 {
+    boolean ignoreInitilization;
 
     public VarDeclarationEmitter(IJSEmitter emitter)
     {
         super(emitter);
+
+        JSConfiguration configuration = ((FlexJSProject) getProject()).config;
+        ignoreInitilization = configuration.getIgnoreDefaultInitilization();
     }
 
     @Override
@@ -180,40 +186,33 @@ public class VarDeclarationEmitter extends JSSubEmitter 
implements
             IExpressionNode enode = 
node.getVariableTypeNode();//getAssignedValueNode();
             if (enode != null)
                 typedef = enode.resolveType(getWalker().getProject());
-            if (typedef != null)
-            {
-                       String defName = typedef.getQualifiedName();
-                       if (defName.equals("int") || defName.equals("uint"))
-                       {
-                               if (node.getParent() != null &&
-                                               node.getParent().getParent() != 
null &&
-                                               
node.getParent().getParent().getNodeID() != ASTNodeID.Op_InID)
-                               {
-                                   write(ASEmitterTokens.SPACE);
-                                   writeToken(ASEmitterTokens.EQUAL);
-                                   write("0");
-                               }
-                       }
-                else if (defName.equals("Boolean"))
-                {
+            if (typedef != null) {
+                String defName = typedef.getQualifiedName();
+                if (defName.equals("int") || defName.equals("uint")) {
                     if (node.getParent() != null &&
                             node.getParent().getParent() != null &&
-                            node.getParent().getParent().getNodeID() != 
ASTNodeID.Op_InID)
-                    {
+                            node.getParent().getParent().getNodeID() != 
ASTNodeID.Op_InID) {
                         write(ASEmitterTokens.SPACE);
                         writeToken(ASEmitterTokens.EQUAL);
-                        write(ASEmitterTokens.FALSE);
+                        write("0");
                     }
-                }
-                else if (defName.equals("Number"))
-                {
-                    if (node.getParent() != null &&
-                            node.getParent().getParent() != null &&
-                            node.getParent().getParent().getNodeID() != 
ASTNodeID.Op_InID)
-                    {
-                        write(ASEmitterTokens.SPACE);
-                        writeToken(ASEmitterTokens.EQUAL);
-                        write("NaN");
+                } else if (!ignoreInitilization) {
+                    if (ignoreInitilization && defName.equals("Boolean")) {
+                        if (node.getParent() != null &&
+                                node.getParent().getParent() != null &&
+                                node.getParent().getParent().getNodeID() != 
ASTNodeID.Op_InID) {
+                            write(ASEmitterTokens.SPACE);
+                            writeToken(ASEmitterTokens.EQUAL);
+                            write(ASEmitterTokens.FALSE);
+                        }
+                    } else if (ignoreInitilization && 
defName.equals("Number")) {
+                        if (node.getParent() != null &&
+                                node.getParent().getParent() != null &&
+                                node.getParent().getParent().getNodeID() != 
ASTNodeID.Op_InID) {
+                            write(ASEmitterTokens.SPACE);
+                            writeToken(ASEmitterTokens.EQUAL);
+                            write("NaN");
+                        }
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/62d53ed4/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
----------------------------------------------------------------------
diff --git 
a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java 
b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
index 6356c88..e21ef65 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
@@ -3961,6 +3961,29 @@ public class Configuration
     }
 
     //
+    // 'compiler.ignore-default-initilization' option
+    //
+
+    /**
+     * Allow the user to set Boolean and Number type to be undefined and 
ignore them being initialised
+     * to false and NaN respectively. Note that use this option breaks 
compatability with ActionScript.
+     */
+    private boolean ignoreDefaultInitilization = true;
+
+    public boolean getIgnoreDefaultInitilization()
+    {
+        return ignoreDefaultInitilization;
+    }
+
+    @Config(advanced = true)
+    @Mapping({ "compiler", "ignore-default-initilization" })
+    @FlexOnly
+    public void setIgnoreDefaultInitilization(ConfigurationValue cv, boolean 
ignoreDefaultInitilization)
+    {
+        this.ignoreDefaultInitilization = ignoreDefaultInitilization;
+    }
+
+    //
     // 'compiler.compress' option (default is true)
     //
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/62d53ed4/compiler/src/main/resources/org/apache/flex/compiler/messages_en.properties
----------------------------------------------------------------------
diff --git 
a/compiler/src/main/resources/org/apache/flex/compiler/messages_en.properties 
b/compiler/src/main/resources/org/apache/flex/compiler/messages_en.properties
index e9b9b79..b23b0b4 100644
--- 
a/compiler/src/main/resources/org/apache/flex/compiler/messages_en.properties
+++ 
b/compiler/src/main/resources/org/apache/flex/compiler/messages_en.properties
@@ -64,6 +64,7 @@ compiler.accessible=generate an accessible SWF
 compiler.compress=enables or disables SWF file compression
 compiler.source-path=list of path elements that form the roots of ActionScript 
class hierarchies
 compiler.actionscript-file-encoding=specifies actionscript file encoding. If 
there is no BOM in the AS3 source files, the compiler will use this file 
encoding.
+compiler.ignore-default-initilization=ignore default initialization of Boolean 
and Numbers and leave them as undefined
 compiler.isolate-styles=enables the compiled application or module to set 
styles that only affect itself and its children
 compiler.context-root=path to replace {context.root} tokens for service 
channel endpoints
 compiler.external-library-path=list of SWC files or directories to compile 
against but to omit from linking

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/62d53ed4/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/COMPCTask.java
----------------------------------------------------------------------
diff --git 
a/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/COMPCTask.java 
b/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/COMPCTask.java
index 178e227..0aabd6c 100644
--- a/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/COMPCTask.java
+++ b/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/COMPCTask.java
@@ -118,6 +118,7 @@ public final class COMPCTask extends FlexTask implements 
DynamicConfigurator
         new ConfigBoolean(new OptionSpec("compiler.es")),
         new ConfigBoolean(new 
OptionSpec("compiler.generate-abstract-syntax-tree")),
         new ConfigBoolean(new OptionSpec("compiler.headless-server")),
+            new ConfigBoolean(new 
OptionSpec("compiler.ignore-default-initilization")),
         new ConfigBoolean(new OptionSpec("compiler.isolate-styles")),
         new ConfigBoolean(new OptionSpec("compiler.keep-all-type-selectors")),
         new ConfigBoolean(new 
OptionSpec("compiler.keep-generated-actionscript", "keep")),

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/62d53ed4/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/MXMLCTask.java
----------------------------------------------------------------------
diff --git 
a/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/MXMLCTask.java 
b/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/MXMLCTask.java
index 613ac2a..6cecb95 100644
--- a/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/MXMLCTask.java
+++ b/flexjs-ant-tasks/src/main/java/org/apache/flex/compiler/ant/MXMLCTask.java
@@ -117,6 +117,7 @@ public final class MXMLCTask extends FlexTask implements 
DynamicConfigurator
         new ConfigBoolean(new OptionSpec("compiler.es")),
         new ConfigBoolean(new 
OptionSpec("compiler.generate-abstract-syntax-tree")),
         new ConfigBoolean(new OptionSpec("compiler.headless-server")),
+            new ConfigBoolean(new 
OptionSpec("compiler.ignore-default-initilization")),
         new ConfigBoolean(new OptionSpec("compiler.isolate-styles")),
         new ConfigBoolean(new OptionSpec("compiler.keep-all-type-selectors")),
         new ConfigBoolean(new 
OptionSpec("compiler.keep-generated-actionscript", "keep")),

Reply via email to