Prevent circular dependencies in $extends

This commit is contained in:
Bán Dénes 2024-04-14 18:07:30 +02:00
parent dd6ff93a89
commit 887220abe3
6 changed files with 17 additions and 4 deletions

View file

@ -69,11 +69,12 @@ exports.inherit = config => traverse(config, config, [], (target, key, val, root
const list = [val]
while (candidates.length) {
const path = candidates.shift()
const other = u.deepcopy(u.deep(root, path))
const other = u.deep(root, path)
a.assert(other, `"${path}" (reached from "${breadcrumbs.join('.')}.$extends") does not name a valid inheritance target!`)
let parents = other.$extends || []
if (a.type(parents)() !== 'array') parents = [parents]
candidates = candidates.concat(parents)
a.assert(!list.includes(other), `"${path}" (reached from "${breadcrumbs.join('.')}.$extends") leads to a circular dependency!`)
list.unshift(other)
}
val = extend.apply(null, list)