@nodescript/core
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -113,5 +113,2 @@ import { isSchemaCompatible } from '../util/index.js'; | ||
this.symtable.set(`node:${node.id}`, sym); | ||
if (node.$uri.startsWith('core:')) { | ||
return this.emitCoreNode(node); | ||
} | ||
this.code.block(`${this.asyncSym()}function ${sym}(ctx) {`, `}`, () => { | ||
@@ -134,28 +131,30 @@ if (this.isNodeCached(node.id)) { | ||
} | ||
emitCoreNode(node) { | ||
switch (node.$uri) { | ||
// Param nodes are not emitted, "params" sym is accessed in-place | ||
case 'core:Param': | ||
return; | ||
// Comment nodes are discarded | ||
case 'core:Comment': | ||
return; | ||
case 'core:Result': | ||
return this.emitResultNode(node); | ||
case 'core:Local': | ||
return this.emitLocalNode(node); | ||
} | ||
} | ||
emitNodeBody(node) { | ||
const resSym = '$r'; | ||
const emitBody = () => { | ||
if (node.isExpanded()) { | ||
this.emitExpandedNode(node); | ||
switch (node.$uri) { | ||
case 'core:Param': return this.emitParamNode(node, resSym); | ||
case 'core:Local': return this.emitLocalNode(node, resSym); | ||
case 'core:Result': return this.emitResultNode(node, resSym); | ||
case 'core:Comment': return; | ||
default: | ||
if (node.isExpanded()) { | ||
this.emitExpandedNode(node, resSym); | ||
} | ||
else { | ||
this.emitRegularNode(node, resSym); | ||
} | ||
} | ||
else { | ||
this.emitRegularNode(node); | ||
} | ||
}; | ||
this.code.line(`let ${resSym};`); | ||
if (this.options.introspect) { | ||
this.code.block('try {', '}', () => { | ||
emitBody(); | ||
if (this.options.introspect) { | ||
this.code.line(`${this.sym.nodeEvaluated}.emit({` + | ||
`nodeId: ${JSON.stringify(node.id)},` + | ||
`result: ${this.awaitSym()}${resSym}` + | ||
`});`); | ||
} | ||
this.code.line(`return ${resSym};`); | ||
}); | ||
@@ -172,23 +171,27 @@ this.code.block('catch (error) {', '}', () => { | ||
emitBody(); | ||
this.code.line(`return ${resSym};`); | ||
} | ||
} | ||
emitResultNode(node) { | ||
const sym = this.getNodeSym(node.id); | ||
emitParamNode(node, resSym) { | ||
const prop = node.getBasePropByKey('key'); | ||
const key = prop?.value; | ||
if (key) { | ||
this.code.line(`${resSym} = params[${JSON.stringify(key)}]`); | ||
} | ||
else { | ||
this.code.line(`${resSym} = undefined;`); | ||
} | ||
} | ||
emitLocalNode(node, resSym) { | ||
const prop = node.getBasePropByKey('key'); | ||
this.code.line(`${resSym} = ctx.getLocal(${JSON.stringify(prop.value)});`); | ||
} | ||
emitResultNode(node, resSym) { | ||
const prop = node.getBasePropByKey('value'); | ||
const expr = this.singlePropExpr(prop, this.graph.metadata.result); | ||
this.code.line(`${this.asyncSym()}function ${sym}(ctx) {` + | ||
`return ${expr};` + | ||
`}`); | ||
this.code.line(`${resSym} = ${expr};`); | ||
} | ||
emitLocalNode(node) { | ||
const sym = this.getNodeSym(node.id); | ||
const prop = node.getBasePropByKey('key'); | ||
this.code.line(`${this.asyncSym()}function ${sym}(ctx) {` + | ||
`return ctx.getLocal(${JSON.stringify(prop.value)});` + | ||
`}`); | ||
} | ||
emitRegularNode(node) { | ||
emitRegularNode(node, resSym) { | ||
const defSym = this.getDefSym(node.ref); | ||
const resSym = `$r`; | ||
this.code.block(`const ${resSym} = ${defSym}.compute({`, `}, ctx);`, () => { | ||
this.code.block(`${resSym} = ${defSym}.compute({`, `}, ctx);`, () => { | ||
this.emitNodeProps(node); | ||
@@ -199,13 +202,5 @@ }); | ||
} | ||
if (this.options.introspect) { | ||
this.code.line(`${this.sym.nodeEvaluated}.emit({` + | ||
`nodeId: ${JSON.stringify(node.id)},` + | ||
`result: ${this.awaitSym()}${resSym}` + | ||
`});`); | ||
} | ||
this.code.line(`return ${this.awaitSym()}${resSym};`); | ||
} | ||
emitExpandedNode(node) { | ||
emitExpandedNode(node, resSym) { | ||
const defSym = this.getDefSym(node.ref); | ||
const resSym = '$r'; | ||
// Expanded nodes always produce an array by | ||
@@ -215,3 +210,3 @@ // repeating the computation per each value of expanded property | ||
const expandProps = props.filter(_ => _.isExpanded()); | ||
this.code.line(`const ${resSym} = []`); | ||
this.code.line(`${resSym} = []`); | ||
const expSyms = []; | ||
@@ -258,9 +253,2 @@ for (const prop of expandProps) { | ||
} | ||
if (this.options.introspect) { | ||
this.code.line(`${this.sym.nodeEvaluated}.emit({` + | ||
`nodeId: ${JSON.stringify(node.id)},` + | ||
`result: ${resSym}` + | ||
`});`); | ||
} | ||
this.code.line(`return ${resSym};`); | ||
} | ||
@@ -344,7 +332,2 @@ emitNodeProps(node) { | ||
nodeResultExpr(node) { | ||
if (node.$uri === 'core:Param') { | ||
const prop = node.getBasePropByKey('key'); | ||
const key = prop ? prop.value : ''; | ||
return `params[${JSON.stringify(key)}]`; | ||
} | ||
const sym = this.getNodeSym(node.id); | ||
@@ -351,0 +334,0 @@ return `${this.awaitSym()}${sym}(ctx)`; |
{ | ||
"name": "@nodescript/core", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "Visual programming language for Browser and Node", |
Sorry, the diff of this file is not supported yet
367
2
122950
2195