Skip to content

Commit fd188ba

Browse files
committed
fix: adding check for unreachability of functions
1 parent 98ef6f7 commit fd188ba

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/validation/getFlowValidation.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ export const getFlowValidation = (
3939
}
4040
}
4141

42+
const functionIdentifiers = new Set(functions?.map(f => f.identifier));
43+
const unreachableFunctionDiagnostics = (flow.nodes?.nodes ?? [])
44+
.filter(n => n?.functionDefinition && !functionIdentifiers.has(n.functionDefinition.identifier))
45+
.map(n => ({
46+
nodeId: n!.id,
47+
parameterIndex: null,
48+
code: 0,
49+
message: `The function definition "${n!.functionDefinition!.identifier}" is not reachable.`,
50+
severity: "error" as const,
51+
}));
52+
53+
if (unreachableFunctionDiagnostics.length > 0) {
54+
return {
55+
isValid: false,
56+
returnType: "void",
57+
diagnostics: unreachableFunctionDiagnostics,
58+
}
59+
}
60+
4261
const sourceCode = generateFlowSourceCode(flow, functions, dataTypes);
4362

4463
// 3. Virtual TypeScript Compilation

0 commit comments

Comments
 (0)