You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Piotr Zarzycki <pi...@gmail.com> on 2017/06/24 08:56:51 UTC

Re: [1/2] git commit: [flex-falcon] [refs/heads/initializers] - make default initialisers configurable

Hi Justin,

Is this mean that if this property is true in config and I set my boolean
property to false it will be ignored ?

var myProperty:Boolean = false;

When I trace it I will see:

undefined

Piotr

2017-06-24 10:46 GMT+02:00 <jm...@apache.org>:

> 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 <jm...@apache.org>
> Authored: Fri Jun 16 12:49:57 2017 +1000
> Committer: Justin Mclean <jm...@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")),
>
>

Re: [1/2] git commit: [flex-falcon] [refs/heads/initializers] - make default initialisers configurable

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> It is default swtich on as I understand ?

No you use it to turn initialisers off.

if you don’t use the compiler option then uninitialised Booleans will default to false and Numbers will default to NaN. This is different to how the current compiler does it.

if you do use it then initialised Boolean and Numbers will be undefined (in JS) and default to the usual false and NaN is AS. This is the current behaviour of the compiler.

Thanks,
Justin

Re: [1/2] git commit: [flex-falcon] [refs/heads/initializers] - make default initialisers configurable

Posted by piotrz <pi...@gmail.com>.
It is default swtich on as I understand ?

Thanks,
Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Re-1-2-git-commit-flex-falcon-refs-heads-initializers-make-default-initialisers-configurable-tp62583p62586.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [1/2] git commit: [flex-falcon] [refs/heads/initializers] - make default initialisers configurable

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> Is this mean that if this property is true in config and I set my boolean
> property to false it will be ignored ?

No.

If you do this it will be false.
var prop:Boolean = false;

If you do this it will be true.
var prop:Boolean = true;

If you do this:
var prop:Boolean;

it will be false and act the same as in ActionScript rather than be undefined as it is currently is in FlexJS.

Thanks,
Justin