You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2017/06/26 15:35:08 UTC
[20/36] git commit: [flex-falcon] [refs/heads/develop] - compiler-jx:
added JSNodeModule to JSTargetType
compiler-jx: added JSNodeModule to JSTargetType
JSNode exports a standalone script that may be run directly by Node.js. JSNodeModule exports a CommonJS module that may be imported into Node with require().
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/530dfed2
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/530dfed2
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/530dfed2
Branch: refs/heads/develop
Commit: 530dfed2fa1cf026bdf6352cab40c6d0b8de44f9
Parents: 5a32df8
Author: Josh Tynjala <jo...@apache.org>
Authored: Fri May 26 16:29:21 2017 -0700
Committer: Josh Tynjala <jo...@apache.org>
Committed: Fri May 26 16:29:21 2017 -0700
----------------------------------------------------------------------
.../apache/flex/compiler/clients/MXMLJSC.java | 31 +++++++++----
.../flex/compiler/clients/MXMLJSCNode.java | 8 +++-
.../compiler/clients/MXMLJSCNodeModule.java | 30 +++++++++++++
.../internal/codegen/js/node/NodePublisher.java | 17 +++++--
.../driver/js/node/NodeModuleBackend.java | 47 ++++++++++++++++++++
5 files changed, 119 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/530dfed2/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
index 1f14259..1c72e74 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -149,8 +149,12 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
SWF("SWF"),
JS_FLEX("JSFlex"),
JS_FLEX_CORDOVA("JSFlexCordova"),
+ //JS without the FlexJS framework
JS_NATIVE("JS"),
- JS_NODE("JSNode");
+ //Node.js application
+ JS_NODE("JSNode"),
+ //Node.js module
+ JS_NODE_MODULE("JSNodeModule");
private String text;
@@ -361,14 +365,23 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
}
break;
case JS_NODE:
- MXMLJSCNode node = new MXMLJSCNode();
- lastCompiler = node;
- result = node.mainNoExit(removeASArgs(args), problems.getProblems(), false);
- if (result != 0 && result != 2)
- {
- break targetloop;
- }
- break;
+ MXMLJSCNode node = new MXMLJSCNode();
+ lastCompiler = node;
+ result = node.mainNoExit(removeASArgs(args), problems.getProblems(), false);
+ if (result != 0 && result != 2)
+ {
+ break targetloop;
+ }
+ break;
+ case JS_NODE_MODULE:
+ MXMLJSCNodeModule nodeModule = new MXMLJSCNodeModule();
+ lastCompiler = nodeModule;
+ result = nodeModule.mainNoExit(removeASArgs(args), problems.getProblems(), false);
+ if (result != 0 && result != 2)
+ {
+ break targetloop;
+ }
+ break;
case JS_NATIVE:
MXMLJSCNative jsc = new MXMLJSCNative();
lastCompiler = jsc;
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/530dfed2/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java
index 49a4013..6ae1999 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java
@@ -174,10 +174,14 @@ public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider,
protected ITargetSettings targetSettings;
protected IJSApplication jsTarget;
private IJSPublisher jsPublisher;
-
+
public MXMLJSCNode()
{
- IBackend backend = new NodeBackend();
+ this(new NodeBackend());
+ }
+
+ protected MXMLJSCNode(IBackend backend)
+ {
workspace = new Workspace();
workspace.setASDocDelegate(new FlexJSASDocDelegate());
project = new FlexJSProject(workspace, backend);
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/530dfed2/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNodeModule.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNodeModule.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNodeModule.java
new file mode 100644
index 0000000..7b65fc1
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNodeModule.java
@@ -0,0 +1,30 @@
+/*
+ *
+ * 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.flex.compiler.clients;
+
+import org.apache.flex.compiler.internal.driver.js.node.NodeModuleBackend;
+
+public class MXMLJSCNodeModule extends MXMLJSCNode
+{
+ public MXMLJSCNodeModule()
+ {
+ super(new NodeModuleBackend());
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/530dfed2/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/node/NodePublisher.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/node/NodePublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/node/NodePublisher.java
index 4d0747c..4a74a65 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/node/NodePublisher.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/node/NodePublisher.java
@@ -29,6 +29,8 @@ import java.util.List;
public class NodePublisher extends JSCPublisher
{
+ public boolean exportModule = false;
+
public NodePublisher(Configuration config, FlexJSProject project)
{
super(project, config);
@@ -63,9 +65,18 @@ public class NodePublisher extends JSCPublisher
protected String getTemplateBody(String projectName)
{
StringBuilder bodyJS = new StringBuilder();
- bodyJS.append("new ");
- bodyJS.append(projectName);
- bodyJS.append("();");
+ if (exportModule)
+ {
+ bodyJS.append("module.exports = ");
+ bodyJS.append(projectName);
+ bodyJS.append(";");
+ }
+ else
+ {
+ bodyJS.append("new ");
+ bodyJS.append(projectName);
+ bodyJS.append("();");
+ }
return bodyJS.toString();
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/530dfed2/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/node/NodeModuleBackend.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/node/NodeModuleBackend.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/node/NodeModuleBackend.java
new file mode 100644
index 0000000..8968894
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/node/NodeModuleBackend.java
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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.flex.compiler.internal.driver.js.node;
+
+import java.util.List;
+
+import org.apache.flex.compiler.config.Configuration;
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.js.node.NodePublisher;
+import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLFlexJSPublisher;
+import org.apache.flex.compiler.internal.driver.js.jsc.JSCBackend;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+
+/**
+ * A concrete implementation of the {@link IBackend} API for Node.js modules.
+ *
+ * @author Josh Tynjala
+ */
+public class NodeModuleBackend extends JSCBackend
+{
+ @Override
+ public MXMLFlexJSPublisher createPublisher(FlexJSProject project,
+ List<ICompilerProblem> errors, Configuration config)
+ {
+ NodePublisher publisher = new NodePublisher(config, project);
+ publisher.exportModule = true;
+ return publisher;
+ }
+}