Skip to content

Commit 5940c15

Browse files
committed
refactor: improve reference value handling in utils.ts for better flow integration
1 parent e7eaba3 commit 5940c15

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/utils.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,9 @@ export function generateFlowSourceCode(
123123
if (!val) return isForInference ? `/* @pos ${nodeId} ${paramIdx} */ {}` : `/* @pos ${nodeId} ${paramIdx} */ undefined`;
124124
if (val.__typename === "ReferenceValue") {
125125
const ref = val as ReferenceValue;
126-
if (!ref.nodeFunctionId) return `/* @pos ${nodeId} ${paramIdx} */ undefined`;
127126
let refCode = typeof ref.inputIndex === "number"
128-
? `p_${sanitizeId(ref.nodeFunctionId)}_${ref.parameterIndex}[${ref.inputIndex}]`
129-
: `node_${sanitizeId(ref.nodeFunctionId)}`;
127+
? `p_${sanitizeId(ref.nodeFunctionId ?? "undefined")}_${ref.parameterIndex}[${ref.inputIndex}]`
128+
: ref.nodeFunctionId ? `node_${sanitizeId(ref.nodeFunctionId)}` : `flow_${sanitizeId(flow?.id ?? "undefined")}`;
130129
ref.referencePath?.forEach(pathObj => {
131130
refCode += `?.${pathObj.path}`;
132131
});
@@ -173,10 +172,9 @@ export function generateFlowSourceCode(
173172
if (!val) return isForInference ? `/* @pos ${nodeId} ${index} */ {}` : `/* @pos ${nodeId} ${index} */ undefined`;
174173
if (val.__typename === "ReferenceValue") {
175174
const ref = val as ReferenceValue;
176-
if (!ref.nodeFunctionId) return `/* @pos ${nodeId} ${index} */ undefined`;
177175
let refCode = typeof ref.inputIndex === "number"
178-
? `p_${sanitizeId(ref.nodeFunctionId)}_${ref.parameterIndex}[${ref.inputIndex}]`
179-
: `node_${sanitizeId(ref.nodeFunctionId)}`;
176+
? `p_${sanitizeId(ref.nodeFunctionId ?? "undefined")}_${ref.parameterIndex}[${ref.inputIndex}]`
177+
: ref.nodeFunctionId ? `node_${sanitizeId(ref.nodeFunctionId)}` : `flow_${sanitizeId(flow?.id ?? "undefined")}`;
180178
ref.referencePath?.forEach(pathObj => {
181179
refCode += `?.${pathObj.path}`;
182180
});

0 commit comments

Comments
 (0)