运行前校验识别循环容器注入的迭代变量\n\n- 数组/字典循环运行时注入 item/index/value, 计数循环注入自定义索引变量\n- 校验器原先只认 flow.variables 与节点输出变量, 对循环体内引用误报未定义变量警告
This commit is contained in:
parent
4af6bd0693
commit
21a400e172
@ -122,6 +122,20 @@ export function validateFlow(flow: FlowDefinition, catalog: Catalog): FlowValida
|
||||
...(flow.variables ?? []).map((item) => item.name),
|
||||
...flow.nodes.map((node) => node.options?.outputVar).filter(Boolean) as string[]
|
||||
]);
|
||||
// 循环容器在运行时向子节点注入迭代变量,静态校验时视为已定义
|
||||
const LOOP_VARS: Record<string, string[]> = {
|
||||
logic_control_array_for_v3: ["item", "index", "value"],
|
||||
logic_control_dictionary_for_v1: ["item", "index", "value"],
|
||||
logic_control_count_for: ["index"]
|
||||
};
|
||||
for (const node of flow.nodes) {
|
||||
const vars = LOOP_VARS[node.componentId];
|
||||
if (vars) {
|
||||
const custom = String(node.values?.count_index ?? "").trim();
|
||||
for (const name of vars) definedVars.add(name);
|
||||
if (node.componentId === "logic_control_count_for" && /^[A-Za-z_]\w*$/.test(custom)) definedVars.add(custom);
|
||||
}
|
||||
}
|
||||
const variableRef = /\$\{\s*([A-Za-z_\u4e00-\u9fa5][\w\u4e00-\u9fa5]*)\s*(?:\.[A-Za-z_]\w*)?\s*\}/g;
|
||||
for (const node of flow.nodes) {
|
||||
const component = componentMap.get(node.componentId);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user