src/core/plugins/inherit/addInheritance.js
function buildConfig(
  config, items, item, inheritableConfigs = {}, visitedItems = []
) {
  let { id } = item

  if (visitedItems.includes(id)) {
    throw new Error(`Item "${id}" has cyclic dependencies`)
  }

  let _extends = item.extends || DEFAULT
  let inheritedConfig = inheritableConfigs[_extends]
  visitedItems.push(id)

  if (!inheritedConfig) {
    let parent = findOneById(items, _extends)

    if (!parent) {
      throw new Error(`Item "${id}" tries to extend a non-existent item`)
    }

    parent = buildConfig(
      config, items, parent, inheritableConfigs, visitedItems
    )
    inheritedConfig = extractInheritableConfig(config, parent)
    inheritableConfigs[parent.id] = inheritedConfig
  }

  return mergeConfigs(inheritedConfig, item)
}
function buildConfig(
  config, items, item, inheritableConfigs = {}, visitedItems = []
) {
  let { id } = item

  if (visitedItems.includes(id)) {
    throw new Error(`Item "${id}" has cyclic dependencies`)
  }

  let _extends = item.extends || DEFAULT
  let inheritedConfig = inheritableConfigs[_extends]
  visitedItems.push(id)

  if (!inheritedConfig) {
    let parent = findOneById(items, _extends)

    if (!parent) {
      throw new Error(`Item "${id}" tries to extend a non-existent item`)
    }

    parent = buildConfig(
      config, items, parent, inheritableConfigs, visitedItems
    )
    inheritedConfig = extractInheritableConfig(config, parent)
    inheritableConfigs[parent.id] = inheritedConfig
  }

  return mergeConfigs(inheritedConfig, item)
}
function buildConfig ( config , items , item , inheritableConfigs = { } , visitedItems = [ ] ) { let { id } = item if ( visitedItems . includes ( id ) ) { throw new Error ( ` ${ id } ` ) } let _extends = item . extends || DEFAULT let inheritedConfig = inheritableConfigs [ _extends ] visitedItems . push ( id ) if ( ! inheritedConfig ) { let parent = findOneById ( items , _extends ) if ( ! parent ) { throw new Error ( ` ${ id } ` ) } parent = buildConfig ( config , items , parent , inheritableConfigs , visitedItems ) inheritedConfig = extractInheritableConfig ( config , parent ) inheritableConfigs [ parent . id ] = inheritedConfig } return mergeConfigs ( inheritedConfig , item ) }
Mutates inheritableConfigs and visitedItems
Mutates inheritableConfigs and visitedItems