From 655b9bf31495816300eb02d0d675024218e48477 Mon Sep 17 00:00:00 2001 From: Alexandre Hajjar Date: Fri, 15 May 2020 13:57:13 +0200 Subject: [PATCH] Cycles: isDisabledBy & replacedBy --- mon-entreprise/test/cycles.test.js | 4 ++-- publicodes/source/cyclesLib.ts | 14 ++++++++++---- publicodes/source/types/index.ts | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mon-entreprise/test/cycles.test.js b/mon-entreprise/test/cycles.test.js index ee44ac294..ae5e7abf5 100644 --- a/mon-entreprise/test/cycles.test.js +++ b/mon-entreprise/test/cycles.test.js @@ -21,8 +21,8 @@ describe('DottedNames graph', () => { expect( cycles, - `\nThe following rules have cycles:\n\t- ${cycles - .map(x => x[0]) + `\nThe cycles have been found in the rules dependencies graph:\n\t- ${cycles + .map((x, idx) => '#' + idx + ':\n\t\t- ' + x.join('\n\t\t- ')) .join('\n\t- ')}\n\n` ).to.be.an('array').that.is.empty }) diff --git a/publicodes/source/cyclesLib.ts b/publicodes/source/cyclesLib.ts index ad0f7c55e..54bed4ea3 100644 --- a/publicodes/source/cyclesLib.ts +++ b/publicodes/source/cyclesLib.ts @@ -41,7 +41,6 @@ export function isCondRuleProp(node: ASTNode): node is CondRuleProp { return isRuleProp(node) && (node as CondRuleProp).rulePropType === 'cond' } -// [XXX] - What about 'rend non applicable'? Unclear what to do in this case, it seems it would create a graph edge in the contrary sense? type ApplicableSi = CondRuleProp & { dottedName: 'applicable si' explanation: ASTNode @@ -942,10 +941,17 @@ function ruleDepsOfRuleNode( rule['applicable si'], rule['non applicable si'] ].filter(x => x !== undefined) as Array - const dependenciesLists = subNodes.map(x => - ruleDepsOfNode(rule.dottedName, x) + const subNodesDeps = subNodes + .map(x => ruleDepsOfNode(rule.dottedName, x)) + .flat(1) + + const isDisabledByDependencies = rule.isDisabledBy.map(x => x.dottedName) + const replacedByDependencies = rule.replacedBy.map( + x => x.referenceNode.dottedName + ) + return [subNodesDeps, isDisabledByDependencies, replacedByDependencies].flat( + 1 ) - return dependenciesLists.flat(1) } export function buildRulesDependencies( diff --git a/publicodes/source/types/index.ts b/publicodes/source/types/index.ts index e83f69e8c..30c3c08a3 100644 --- a/publicodes/source/types/index.ts +++ b/publicodes/source/types/index.ts @@ -50,8 +50,8 @@ export type ParsedRule = Rule & { formule?: any evaluate?: Function explanation?: any - isDisabledBy?: Array - replacedBy?: Array + isDisabledBy: Array + replacedBy: Array rulePropType?: string jsx?: Function cotisation?: Partial<{