<commit_before>import leftHandIdentifiers from './leftHandIdentifiers';

/**
 * Represents a CoffeeScript scope and its bindings.
 *
 * @param {?Scope} parent
 * @constructor
 */
export default class Scope {
  constructor(parent) {
    this.parent = parent;
    this.bindings = Object.create(parent ? parent.bindings : null);
  }

  /**
   * @param {string} name
   * @returns {?Object}
   */
  getBinding(name) {
    return this.bindings[this.key(name)] || null;
  }

  /**
   * @param {string} name
   * @param {Object} node
   */
  declares(name, node) {
    const key = this.key(name);
    this.bindings[key] = node;
  }

  /**
   * @param {string} name
   * @param {Object} node
   */
  assigns(name, node) {
    if (!this.bindings[this.key(name)]) {
      // Not defined in this or any parent scope.
      this.declares(name, node);
    }
  }

  /**
   * @param {string} name
   * @returns {string}
   * @private
   */
  key(name) {
    return '$' + name;
  }

  /**
   * @param {string} key
   * @returns {string}
   * @private
   */
  unkey(key) {
    return key.slice(1);
  }

  /**
   * Handles declarations or assigns for any bindings for a given node.
   *
   * @param {Object} node
   */
  processNode(node) {
    if (node.type === 'AssignOp') {
      leftHandIdentifiers(node.assignee).forEach(identifier =>
        this.assigns(identifier.data, identifier)
      );
    }

    if (node.type === 'Function') {
      node.parameters.forEach(parameter =>
        this.declares(parameter.data, parameter)
      );
    }
  }
<commit_msg>Use a switch statement instead of multiple `if`s.<commit_after>import leftHandIdentifiers from './leftHandIdentifiers';

/**
 * Represents a CoffeeScript scope and its bindings.
 *
 * @param {?Scope} parent
 * @constructor
 */
export default class Scope {
  constructor(parent) {
    this.parent = parent;
    this.bindings = Object.create(parent ? parent.bindings : null);
  }

  /**
   * @param {string} name
   * @returns {?Object}
   */
  getBinding(name) {
    return this.bindings[this.key(name)] || null;
  }

  /**
   * @param {string} name
   * @param {Object} node
   */
  declares(name, node) {
    const key = this.key(name);
    this.bindings[key] = node;
  }

  /**
   * @param {string} name
   * @param {Object} node
   */
  assigns(name, node) {
    if (!this.bindings[this.key(name)]) {
      // Not defined in this or any parent scope.
      this.declares(name, node);
    }
  }

  /**
   * @param {string} name
   * @returns {string}
   * @private
   */
  key(name) {
    return '$' + name;
  }

  /**
   * @param {string} key
   * @returns {string}
   * @private
   */
  unkey(key) {
    return key.slice(1);
  }

  /**
   * Handles declarations or assigns for any bindings for a given node.
   *
   * @param {Object} node
   */
  processNode(node) {
    switch (node.type) {
      case 'AssignOp':
        leftHandIdentifiers(node.assignee).forEach(identifier =>
          this.assigns(identifier.data, identifier)
        );
        break;

      case 'Function':
        node.parameters.forEach(parameter =>
          this.declares(parameter.data, parameter)
        );
        break;
    }
  }

{'fraction_non_alphanumeric': 0.15102685624012638, 'fraction_numerical': 0.000631911532385466, 'mean_word_length': 2.404301075268817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3469276', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1048, 'n_words': 235}