Cycles: isDisabledBy & replacedBy

cycles-detection-with-context
Alexandre Hajjar 2020-05-15 13:57:13 +02:00
parent 5fcc7500c9
commit 655b9bf314
3 changed files with 14 additions and 8 deletions

View File

@ -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
})

View File

@ -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<Names extends string>(
rule['applicable si'],
rule['non applicable si']
].filter(x => x !== undefined) as Array<ASTNode>
const dependenciesLists = subNodes.map(x =>
ruleDepsOfNode<Names>(rule.dottedName, x)
const subNodesDeps = subNodes
.map(x => ruleDepsOfNode<Names>(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<Names extends string>(

View File

@ -50,8 +50,8 @@ export type ParsedRule<Name extends string = string> = Rule & {
formule?: any
evaluate?: Function
explanation?: any
isDisabledBy?: Array<any>
replacedBy?: Array<any>
isDisabledBy: Array<any>
replacedBy: Array<any>
rulePropType?: string
jsx?: Function
cotisation?: Partial<{