Skip to content

Commit e54fb78

Browse files
authored
Merge pull request #70 from code0-tech/feat/#68
Also support validations for nodes and trigger directly without a parameter
2 parents 3e1c361 + 9fe3f65 commit e54fb78

3 files changed

Lines changed: 662 additions & 8 deletions

File tree

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface ValidationResult {
2525
code: number
2626
severity: "error" | "warning"
2727
nodeId?: NodeFunction["id"]
28-
parameterIndex?: number
28+
parameterIndex?: number | null
2929
}>;
3030
}
3131

@@ -142,7 +142,7 @@ export function generateFlowSourceCode(
142142
return isForInference ? `/* @pos ${nodeId} ${paramIdx} */ ({} as any)` : `/* @pos ${nodeId} ${paramIdx} */ undefined`;
143143
}).join(", ");
144144

145-
const funcName = `fn_${node.functionDefinition.identifier.replace(/::/g, '_')}`;
145+
const funcName = `/* @pos ${nodeId} null */ fn_${node.functionDefinition.identifier.replace(/::/g, '_')}`;
146146
const call = `${funcName}(${args})`;
147147
// Add position comment only for nested calls (when called from within an argument)
148148
if (parentNodeId !== undefined && parentParamIndex !== undefined) {
@@ -214,7 +214,7 @@ export function generateFlowSourceCode(
214214
const funcName = `fn_${node?.functionDefinition?.identifier?.replace(/::/g, '_')}`;
215215
const needsAnyCast = args.includes("undefined");
216216
const isReturnNode = node.functionDefinition.identifier === "std::control::return";
217-
let code = `${indent}${isReturnNode ? "return " : `const ${varName} = `}${funcName}(${args})${needsAnyCast ? "" : ""} ;\n`;
217+
let code = `${indent}${isReturnNode ? "return " : `const ${varName} = `}/* @pos ${nodeId} null */ ${funcName}(${args})${needsAnyCast ? "" : ""} ;\n`;
218218
if (node.nextNodeId) code += generateNodeCode(node.nextNodeId, indent);
219219
return code;
220220
};
@@ -229,7 +229,7 @@ export function generateFlowSourceCode(
229229
if (p?.value?.__typename === "NodeFunctionIdWrapper" && p.value.id) subTreeIds.add(p.value.id);
230230
}));
231231

232-
const flowCode = flow ? `const flow_${sanitizeId(flow.id ?? "")} = flow(${flow.settings?.nodes?.map((setting, index) => `/* @pos undefined ${index} */ ${stringify(setting?.value)}`).join(", ") ?? ""});` : ""
232+
const flowCode = flow ? `const flow_${sanitizeId(flow.id ?? "")} = /* @pos null null */ flow(${flow.settings?.nodes?.map((setting, index) => `/* @pos null ${index} */ ${stringify(setting?.value)}`).join(", ") ?? ""});` : ""
233233

234234
const executionCode = nodes
235235
.filter(n => n?.id && !nextNodeIds.has(n.id) && !subTreeIds.has(n.id))

src/validation/getFlowValidation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const getFlowValidation = (
2828
// We ignore this in flow validation too because we might generate code for incomplete flows.
2929

3030
let nodeId: NodeFunction['id'] | undefined;
31-
let parameterIndex: number | undefined;
31+
let parameterIndex: number | null = null;
3232

3333
if (d.start !== undefined) {
3434
const fullText = sourceFile.getFullText();
@@ -40,7 +40,7 @@ export const getFlowValidation = (
4040
const searchText = fullText.substring(searchStart, searchEnd);
4141

4242
// Find all @pos comments in the search range
43-
const posRegex = /\/\* @pos ([^ ]+) (\d+) \*\//g;
43+
const posRegex = /\/\* @pos ([^ ]+) (\d+|null) \*\//g;
4444
let match;
4545
let closestMatch: RegExpExecArray | null = null;
4646
let closestCommentEnd = -1;
@@ -62,7 +62,7 @@ export const getFlowValidation = (
6262
}
6363

6464
if (closestMatch) {
65-
nodeId = closestMatch[1] === "undefined" ? undefined : closestMatch[1] as NodeFunction['id'];
65+
nodeId = closestMatch[1] === "null" ? null : closestMatch[1] as NodeFunction['id'];
6666
parameterIndex = parseInt(closestMatch[2], 10);
6767
}
6868
}
@@ -72,7 +72,7 @@ export const getFlowValidation = (
7272
code: d.code,
7373
severity: "error" as const,
7474
nodeId,
75-
parameterIndex
75+
parameterIndex: typeof parameterIndex == "number" && Number.isSafeInteger(parameterIndex) ? parameterIndex : null,
7676
};
7777
}).filter((e) => e !== null);
7878

0 commit comments

Comments
 (0)