<commit_before>const loadModules = require('./loadModules')
const listModules = require('./listModules')
const { asClass, asFunction, asValue } = require('./registrations')
const AwilixResolutionError = require('./AwilixResolutionError')
const nameValueToObject = require('./nameValueToObject')
const Lifetime = require('./Lifetime')
const last = require('./last')

/**
 * Family tree symbol.
 * @type {Symbol}
 */
const FAMILY_TREE = Symbol('familyTree')

/**
 * Creates an Awilix container instance.
 *
 * @param {Function} options.require
 * The require function to use. Defaults to require.
 *
 * @return {object}
 * The container.
 */
module.exports = function createContainer (options, __parentContainer) {
  options = Object.assign({}, options)

  // The resolution stack is used to keep track
  // of what modules are being resolved, so when
  // an error occurs, we have something to present
  // to the poor developer who fucked up.
  let resolutionStack = []

  // For performance reasons, we store
  // the rolled-up registrations when starting a resolve.
  let __tempRegistrations = null

  // Internal registration store.
  const registrations = {}

  // The container being exposed.
  const container = {
    /**
     * Getter for the rolled up registrations that merges the container family tree.
     *
     * @return {object}
     */
    get registrations () {
      return rollUpRegistrations()
    },

    /**
     * Used by util.inspect (which us used by console.log).
     */
    inspect: (depth, opts) => {
      return `[AwilixContainer (${__parentContainer ? 'scoped, ' : ''}registrations: ${Object.keys(container.registrations).length})]`
    }
  }

  // Track the family tree.
  const familyTree = __parentContainer
    ? [container].concat(__parentContainer[FAMILY_TREE])
    : [container]

  /**
   * The family tree, used for scoping.
   *
   * @api private
   * @type {object[]}
   */
  container[FAMILY_TREE] = familyTree

  /**
   * We need a cache for storing singletons and scoped resolutions.
   * The key is the registration name, value is the resolved.. value.
   * @type {object}
   */
  container.cache = {}

  // Partially applied to the loadModules function.
  const _loadModulesDeps = {
    require: options.require || function (uri) { return require(uri) },
    listModules: listModules,
    container: container
  }

  /**
   * The `Proxy` that is passed to functions so they can resolve their dependencies without
   * knowing where they come from. I call it the "cradle" because
   * it is where registered things come to life at resolution-time.
   */
  const cradle = new Proxy({}, {
    /**
     * The `get` handler is invoked whenever a get-call for `container.cradle.*` is made.
     *
     * @param  {object} target
     * The proxy target. Irrelevant.
     *
     * @param  {string} name
     * The property name.
     *
     * @return {*}
     * Whatever the resolve call returns.
     */
    get: (target, name) => resolve(name),

    /**
     * Setting things on the cradle throws an error.
     *
     * @param  {object} target
     * @param  {string} name
     */
    set: (target, name, value) => {
      throw new Error(`Attempted setting property "${name}" on container cradle - this is not allowed.`)
    },

    has: (target, name) => {
      return !!rollUpRegistrations()[name]
    }
  })

  container.cradle = cradle

  /**
   * Rolls up registrations from the family tree.
   *
   * @return {object}
   * The merged registrations object.
   */
  const rollUpRegistrations = () => {
    return Object.assign(
      {},
      __parentContainer && __parentContainer.registrations,
      registrations
    )
  }<commit_msg>Added 'has' comments<commit_after>const loadModules = require('./loadModules')
const listModules = require('./listModules')
const { asClass, asFunction, asValue } = require('./registrations')
const AwilixResolutionError = require('./AwilixResolutionError')
const nameValueToObject = require('./nameValueToObject')
const Lifetime = require('./Lifetime')
const last = require('./last')

/**
 * Family tree symbol.
 * @type {Symbol}
 */
const FAMILY_TREE = Symbol('familyTree')

/**
 * Creates an Awilix container instance.
 *
 * @param {Function} options.require
 * The require function to use. Defaults to require.
 *
 * @return {object}
 * The container.
 */
module.exports = function createContainer (options, __parentContainer) {
  options = Object.assign({}, options)

  // The resolution stack is used to keep track
  // of what modules are being resolved, so when
  // an error occurs, we have something to present
  // to the poor developer who fucked up.
  let resolutionStack = []

  // For performance reasons, we store
  // the rolled-up registrations when starting a resolve.
  let __tempRegistrations = null

  // Internal registration store.
  const registrations = {}

  // The container being exposed.
  const container = {
    /**
     * Getter for the rolled up registrations that merges the container family tree.
     *
     * @return {object}
     */
    get registrations () {
      return rollUpRegistrations()
    },

    /**
     * Used by util.inspect (which us used by console.log).
     */
    inspect: (depth, opts) => {
      return `[AwilixContainer (${__parentContainer ? 'scoped, ' : ''}registrations: ${Object.keys(container.registrations).length})]`
    }
  }

  // Track the family tree.
  const familyTree = __parentContainer
    ? [container].concat(__parentContainer[FAMILY_TREE])
    : [container]

  /**
   * The family tree, used for scoping.
   *
   * @api private
   * @type {object[]}
   */
  container[FAMILY_TREE] = familyTree

  /**
   * We need a cache for storing singletons and scoped resolutions.
   * The key is the registration name, value is the resolved.. value.
   * @type {object}
   */
  container.cache = {}

  // Partially applied to the loadModules function.
  const _loadModulesDeps = {
    require: options.require || function (uri) { return require(uri) },
    listModules: listModules,
    container: container
  }

  /**
   * The `Proxy` that is passed to functions so they can resolve their dependencies without
   * knowing where they come from. I call it the "cradle" because
   * it is where registered things come to life at resolution-time.
   */
  const cradle = new Proxy({}, {
    /**
     * The `get` handler is invoked whenever a get-call for `container.cradle.*` is made.
     *
     * @param  {object} target
     * The proxy target. Irrelevant.
     *
     * @param  {string} name
     * The property name.
     *
     * @return {*}
     * Whatever the resolve call returns.
     */
    get: (target, name) => resolve(name),

    /**
     * Setting things on the cradle throws an error.
     *
     * @param  {object} target
     * @param  {string} name
     */
    set: (target, name, value) => {
      throw new Error(`Attempted setting property "${name}" on container cradle - this is not allowed.`)
    },

    /**
     * The `has` handler is invoked whenever an in-call for `<dependency> in container.cradle` is made.
     *
     * @param  {object} target
     * The proxy target. Irrelevant.
     *
     * @param  {string} name
     * The property name.
     *
     * @return {boolean}
     * True is the dependency is registered, otherwise false
     */
    has: (target, name) => {
      return !!rollUpRegistrations()[name]
    }
  })

  container.cradle = cradle

  /**
   * Rolls up registrations from the family tree.
   *
   * @return {object}
   * The merged registrations object.
   */
  const rollUpRegistrations = () => {
    return Object.assign(
      {},
      __parentContainer && __parentContainer.registrations,
      registrations
    )
  }
{'fraction_non_alphanumeric': 0.11731988099857715, 'fraction_numerical': 0.0, 'mean_word_length': 2.7846304454233968, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1512933', 'n_tokens_mistral': 2261, 'n_tokens_neox': 2223, 'n_words': 735}