flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joshtynj...@apache.org
Subject [1/5] git commit: [flex-falcon] [refs/heads/develop] - compiler-jx: MXMLFlexJSEmitter does not stringify script nodes because this fails to generate source maps.
Date Thu, 23 Mar 2017 22:15:10 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 702006281 -> 548283ede


compiler-jx: MXMLFlexJSEmitter does not stringify script nodes because this fails to generate
source maps.

Instead, it saves the script nodes for later, and walks them normally.


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

Branch: refs/heads/develop
Commit: d939b6267d98cd62e0a6adcfa575b184e1dd8ac4
Parents: 51ddb85
Author: Josh Tynjala <joshtynjala@apache.org>
Authored: Fri Mar 17 15:48:39 2017 -0700
Committer: Josh Tynjala <joshtynjala@apache.org>
Committed: Fri Mar 17 15:48:39 2017 -0700

----------------------------------------------------------------------
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java  | 112 ++++++++-----------
 1 file changed, 49 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d939b626/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
index 21aef44..0b87cd6 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
@@ -76,6 +76,7 @@ import org.apache.flex.compiler.tree.metadata.IMetaTagsNode;
 import org.apache.flex.compiler.tree.mxml.*;
 import org.apache.flex.compiler.units.ICompilationUnit;
 import org.apache.flex.compiler.utils.NativeUtils;
+import org.apache.flex.compiler.visitor.IBlockWalker;
 import org.apache.flex.compiler.visitor.mxml.IMXMLBlockWalker;
 import org.apache.flex.swc.ISWC;
 
@@ -99,7 +100,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     private ArrayList<MXMLDescriptorSpecifier> instances;
     // all instances in the document AND its subdocuments
     private ArrayList<MXMLDescriptorSpecifier> allInstances = new ArrayList<MXMLDescriptorSpecifier>();
-    private ArrayList<MXMLScriptSpecifier> scripts;
+    private ArrayList<IMXMLScriptNode> scripts;
     //private ArrayList<MXMLStyleSpecifier> styles;
     private IClassDefinition classDefinition;
     private IClassDefinition documentDefinition;
@@ -344,7 +345,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         events = new ArrayList<MXMLEventSpecifier>();
         instances = new ArrayList<MXMLDescriptorSpecifier>();
-        scripts = new ArrayList<MXMLScriptSpecifier>();
+        scripts = new ArrayList<IMXMLScriptNode>();
         //styles = new ArrayList<MXMLStyleSpecifier>();
 
         currentInstances = new ArrayList<MXMLDescriptorSpecifier>();
@@ -411,7 +412,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         ArrayList<MXMLDescriptorSpecifier> oldDescriptorTree;
         MXMLDescriptorSpecifier oldPropertiesTree;
         ArrayList<MXMLEventSpecifier> oldEvents;
-        ArrayList<MXMLScriptSpecifier> oldScripts;
+        ArrayList<IMXMLScriptNode> oldScripts;
         ArrayList<MXMLDescriptorSpecifier> oldCurrentInstances;
         ArrayList<MXMLDescriptorSpecifier> oldInstances;
         ArrayList<MXMLDescriptorSpecifier> oldCurrentPropertySpecifiers;
@@ -431,7 +432,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         oldInstances = instances;
         instances = new ArrayList<MXMLDescriptorSpecifier>();
         oldScripts = scripts;
-        scripts = new ArrayList<MXMLScriptSpecifier>();
+        scripts = new ArrayList<IMXMLScriptNode>();
         //styles = new ArrayList<MXMLStyleSpecifier>();
 
         oldCurrentInstances = currentInstances;
@@ -1293,13 +1294,49 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
     protected void emitScripts()
     {
-        for (MXMLScriptSpecifier script : scripts)
+        for (IMXMLScriptNode node : scripts)
         {
-            String output = script.output();
+            IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
+                    .getASEmitter();
 
-            if (!output.equals(""))
+            int len = node.getChildCount();
+            if (len > 0)
             {
-                writeNewline(output);
+                for (int i = 0; i < len; i++)
+                {
+                    IASNode cnode = node.getChild(i);
+                    if (cnode.getNodeID() == ASTNodeID.VariableID) {
+                        ((JSFlexJSEmitter) asEmitter).getModel().getVars().add((IVariableNode)
cnode);
+                    } else {
+                        if (cnode.getNodeID() == ASTNodeID.BindableVariableID) {
+                            IVariableNode variableNode = (IVariableNode) cnode;
+                            BindableVarInfo bindableVarInfo = new BindableVarInfo();
+                            bindableVarInfo.isStatic = variableNode.hasModifier(ASModifier.STATIC);;
+                            bindableVarInfo.namespace = variableNode.getNamespace();
+                            IMetaTagsNode metaTags = variableNode.getMetaTags();
+                            if (metaTags != null) {
+                                IMetaTagNode[] tags = metaTags.getAllTags();
+                                if (tags.length > 0)
+                                    bindableVarInfo.metaTags = tags;
+                            }
+
+                            bindableVarInfo.type = variableNode.getVariableTypeNode().resolveType(getMXMLWalker().getProject()).getQualifiedName();
+                            ((JSFlexJSEmitter) asEmitter).getModel().getBindableVars().put(variableNode.getName(),
bindableVarInfo);
+                        }
+                    }
+
+                    if (!(cnode instanceof IImportNode))
+                    {
+                        asEmitter.getWalker().walk(cnode);
+                        write(ASEmitterTokens.SEMICOLON.getToken());
+
+                        if (i == len - 1)
+                            indentPop();
+
+                        writeNewline();
+                        writeNewline();
+                    }
+                }
             }
         }
     }
@@ -2061,61 +2098,10 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     @Override
     public void emitScript(IMXMLScriptNode node)
     {
-        IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
-                .getASEmitter();
-
-        String nl = ASEmitterTokens.NEW_LINE.getToken();
-
-        StringBuilder sb = null;
-        MXMLScriptSpecifier scriptSpecifier = null;
-
-        int len = node.getChildCount();
-        if (len > 0)
-        {
-            for (int i = 0; i < len; i++)
-            {
-                IASNode cnode = node.getChild(i);
-                if (cnode.getNodeID() == ASTNodeID.VariableID) {
-                    ((JSFlexJSEmitter) asEmitter).getModel().getVars().add((IVariableNode)
cnode);
-                } else {
-                    if (cnode.getNodeID() == ASTNodeID.BindableVariableID) {
-                        IVariableNode variableNode = (IVariableNode) cnode;
-                        BindableVarInfo bindableVarInfo = new BindableVarInfo();
-                        bindableVarInfo.isStatic = variableNode.hasModifier(ASModifier.STATIC);;
-                        bindableVarInfo.namespace = variableNode.getNamespace();
-                        IMetaTagsNode metaTags = variableNode.getMetaTags();
-                        if (metaTags != null) {
-                            IMetaTagNode[] tags = metaTags.getAllTags();
-                            if (tags.length > 0)
-                                bindableVarInfo.metaTags = tags;
-                        }
-
-                        bindableVarInfo.type = variableNode.getVariableTypeNode().resolveType(getMXMLWalker().getProject()).getQualifiedName();
-                        ((JSFlexJSEmitter) asEmitter).getModel().getBindableVars().put(variableNode.getName(),
bindableVarInfo);
-                    }
-                }
-
-                if (!(cnode instanceof IImportNode))
-                {
-                    sb = new StringBuilder();
-                    scriptSpecifier = new MXMLScriptSpecifier();
-
-                    sb.append(asEmitter.stringifyNode(cnode));
-
-                    sb.append(ASEmitterTokens.SEMICOLON.getToken());
-
-                    if (i == len - 1)
-                        indentPop();
-
-                    sb.append(nl);
-                    sb.append(nl);
-
-                    scriptSpecifier.fragment = sb.toString();
-
-                    scripts.add(scriptSpecifier);
-                }
-            }
-        }
+        //save the script for emitting later in emitScripts()
+        //previously, we stringified the node and saved that instead of the
+        //node, but source maps don't work when you stringify a node -JT
+        scripts.add(node);
     }
 
     @Override


Mime
View raw message