@nodescript/core
Advanced tools
Comparing version 0.22.0 to 0.22.1
@@ -152,3 +152,3 @@ import { GraphSchema } from '../schema/index.js'; | ||
const order = []; | ||
const node = this.getNodeById(nodeId ?? this.rootNodeId); | ||
const node = this.getNodeById(nodeId); | ||
if (node) { | ||
@@ -155,0 +155,0 @@ this._computeOrder(order, node); |
@@ -17,7 +17,3 @@ import { isSchemaCompatible } from '../util/index.js'; | ||
compileEsm(graph, options = {}) { | ||
const node = graph.getNodeById(options.rootNodeId ?? graph.rootNodeId); | ||
if (!node) { | ||
throw new CompilerError('Root node not found'); | ||
} | ||
const gcc = new GraphCompilerContext(graph, node, options); | ||
const gcc = new GraphCompilerContext(graph, options); | ||
return gcc.compileEsm(); | ||
@@ -27,5 +23,4 @@ } | ||
class GraphCompilerContext { | ||
constructor(graph, rootNode, options = {}) { | ||
constructor(graph, options = {}) { | ||
this.graph = graph; | ||
this.rootNode = rootNode; | ||
// Counters tracked for each emitted symbol to ensure variable name uniqueness | ||
@@ -46,3 +41,3 @@ this.symCounters = new Map(); | ||
this.options = { | ||
rootNodeId: rootNode.id, | ||
rootNodeId: '', | ||
comments: false, | ||
@@ -55,3 +50,3 @@ introspect: false, | ||
}; | ||
this.order = this.options.emitAll ? graph.nodes : graph.computeOrder(rootNode.id); | ||
this.order = this.computeOrder(); | ||
this.linkMap = graph.computeLinkMap(); | ||
@@ -72,2 +67,14 @@ this.async = this.order.some(_ => _.$def.metadata.async); | ||
} | ||
get rootNode() { | ||
return this.graph.getNodeById(this.options.rootNodeId); | ||
} | ||
computeOrder() { | ||
if (this.options.emitAll) { | ||
return this.graph.nodes; | ||
} | ||
if (this.rootNode) { | ||
return this.graph.computeOrder(this.rootNode.id); | ||
} | ||
return []; | ||
} | ||
emitImports() { | ||
@@ -116,4 +123,9 @@ this.emitComment('Imports'); | ||
this.emitComment('Result'); | ||
const expr = this.nodeResultExpr(this.rootNode); | ||
this.code.line(`return ${expr};`); | ||
if (this.rootNode) { | ||
const expr = this.nodeResultExpr(this.rootNode); | ||
this.code.line(`return ${expr};`); | ||
} | ||
else { | ||
this.code.line(`return undefined;`); | ||
} | ||
} | ||
@@ -120,0 +132,0 @@ emitNode(node) { |
{ | ||
"name": "@nodescript/core", | ||
"version": "0.22.0", | ||
"version": "0.22.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "Visual programming language for Browser and Node", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
134467
2398