Skip to content

Commit 1811be3

Browse files
committed
feat: update generateNodeCode to use identifier instead of id for SubFlowValue
1 parent 9c1e80a commit 1811be3

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ export function generateFlowSourceCode(
109109
): string {
110110
const nodes = flow?.nodes?.nodes || [];
111111
const funcMap = new Map(functions?.map(f => [f.identifier, f]));
112-
const visited = new Set<NodeFunction['id'] | FunctionDefinition['id']>();
112+
const visited = new Set<NodeFunction['id']>();
113113

114-
const generateNodeCode = (id: NodeFunction['id'] | FunctionDefinition['id'], indent: string = ""): string => {
114+
const generateNodeCode = (id: NodeFunction['id'] | FunctionDefinition['identifier'], indent: string = ""): string => {
115115
const node = nodes.find(n => n?.id === id);
116116
if (!node || !node.functionDefinition) return "";
117-
visited.add(id);
117+
if (id?.includes("NodeFunction")) visited.add(id as NodeFunction['id']);
118118

119119
const funcDef = funcMap.get(node.functionDefinition.identifier);
120120
if (!funcDef) return `${indent}// Error: Function ${node.functionDefinition.identifier} not found\n`;
@@ -159,14 +159,14 @@ export function generateFlowSourceCode(
159159
} else if (node.functionDefinition.identifier === "std::control::if") {
160160
code += `const ${varName} = /* @pos ${id} null */ ${funcName}(${args.join(", ")})${needsAnyCast ? "" : ""} ;\n`
161161
code += `if(${args[0]}) {
162-
${generateNodeCode(((node.parameters?.nodes?.[1]?.value as SubFlowValue)?.startingNodeId || (node.parameters?.nodes?.[1]?.value as SubFlowValue)?.functionDefinition?.id), indent + " ")}
162+
${generateNodeCode(((node.parameters?.nodes?.[1]?.value as SubFlowValue)?.startingNodeId || (node.parameters?.nodes?.[1]?.value as SubFlowValue)?.functionDefinition?.identifier), indent + " ")}
163163
}`
164164
} else if (node.functionDefinition.identifier === "std::control::if_else") {
165165
code += `const ${varName} = /* @pos ${id} null */ ${funcName}(${args.join(", ")})${needsAnyCast ? "" : ""} ;\n`
166166
code += `if(${args[0]}) {
167-
${generateNodeCode(((node.parameters?.nodes?.[1]?.value as SubFlowValue)?.startingNodeId || (node.parameters?.nodes?.[1]?.value as SubFlowValue)?.functionDefinition?.id), indent + " ")}
167+
${generateNodeCode(((node.parameters?.nodes?.[1]?.value as SubFlowValue)?.startingNodeId || (node.parameters?.nodes?.[1]?.value as SubFlowValue)?.functionDefinition?.identifier), indent + " ")}
168168
} else {
169-
${generateNodeCode(((node.parameters?.nodes?.[2]?.value as SubFlowValue)?.startingNodeId || (node.parameters?.nodes?.[2]?.value as SubFlowValue)?.functionDefinition?.id), indent + " ")}
169+
${generateNodeCode(((node.parameters?.nodes?.[2]?.value as SubFlowValue)?.startingNodeId || (node.parameters?.nodes?.[2]?.value as SubFlowValue)?.functionDefinition?.identifier), indent + " ")}
170170
}`
171171
} else {
172172
code += `const ${varName} = /* @pos ${id} null */ ${funcName}(${args.join(", ")})${needsAnyCast ? "" : ""} ;\n`

0 commit comments

Comments
 (0)