Change indirection and preprocessing symbols
This commit is contained in:
parent
1910e93d71
commit
29503614cc
3 changed files with 11 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
|||
const u = require('./utils')
|
||||
const a = require('./assert')
|
||||
|
||||
const unnest = exports.unnest = (config) => {
|
||||
const unnest = exports.unnest = config => {
|
||||
if (a.type(config)() !== 'object') return config
|
||||
const result = {}
|
||||
for (const [key, val] of Object.entries(config)) {
|
||||
|
@ -14,7 +14,7 @@ const _extend = exports._extend = (to, from) => {
|
|||
const to_type = a.type(to)()
|
||||
const from_type = a.type(from)()
|
||||
if (from === undefined || from === null) return to
|
||||
if (from === '!!unset') return undefined
|
||||
if (from === '$unset') return undefined
|
||||
if (to_type != from_type) return from
|
||||
if (from_type == 'object') {
|
||||
const res = u.deepcopy(to)
|
||||
|
@ -47,21 +47,21 @@ const _inherit = exports._inherit = (config, root, breadcrumbs) => {
|
|||
for (const [key, val] of Object.entries(config)) {
|
||||
breadcrumbs.push(key)
|
||||
let newval = _inherit(val, root, breadcrumbs)
|
||||
if (newval && newval.extends !== undefined) {
|
||||
let candidates = u.deepcopy(newval.extends)
|
||||
if (newval && newval.$extends !== undefined) {
|
||||
let candidates = u.deepcopy(newval.$extends)
|
||||
if (a.type(candidates)() !== 'array') candidates = [candidates]
|
||||
const list = [newval]
|
||||
while (candidates.length) {
|
||||
const path = candidates.shift()
|
||||
const other = u.deepcopy(u.deep(root, path))
|
||||
a.assert(other, `"${path}" (reached from "${breadcrumbs.join('.')}.extends") does not name a valid inheritance target!`)
|
||||
let parents = other.extends || []
|
||||
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)
|
||||
list.unshift(other)
|
||||
}
|
||||
newval = extend.apply(this, list)
|
||||
delete newval.extends
|
||||
delete newval.$extends
|
||||
}
|
||||
result[key] = newval
|
||||
breadcrumbs.pop()
|
||||
|
@ -69,4 +69,4 @@ const _inherit = exports._inherit = (config, root, breadcrumbs) => {
|
|||
return result
|
||||
}
|
||||
|
||||
const inherit = exports.inherit = (config) => _inherit(config, config, [])
|
||||
const inherit = exports.inherit = config => _inherit(config, config, [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue