<commit_before>var traverse = require("../../traverse");
var util     = require("../../util");
var t        = require("../../types");

exports.ClassDeclaration = function (node, parent, file, scope) {
  var closure = true;
  if (t.isProgram(parent) || t.isBlockStatement(parent)) {
    closure = false;
  }

  var newNode = new Class(node, file, scope, closure).run();
  if (closure || t.isFunctionExpression(newNode)) {
    return t.variableDeclaration("let", [
      t.variableDeclarator(node.id, newNode)
    ]);
  } else {
    return newNode;
  }
};

exports.ClassExpression = function (node, parent, file, scope) {
  return new Class(node, file, scope, true).run();
};

/**
 * Description
 *
 * @param {Node} node
 * @param {File} file
 * @param {Scope} scope
 * @param {Boolean} closure
 */

function Class(node, file, scope, closure) {
  this.closure = closure;
  this.scope   = scope;
  this.node    = node;
  this.file    = file;

  this.hasInstanceMutators = false;
  this.hasStaticMutators   = false;

  this.instanceMutatorMap = {};
  this.staticMutatorMap   = {};
  this.hasConstructor     = false;
  this.className          = node.id || file.generateUidIdentifier("class", scope);<commit_msg>better ClassDeclarations in expression contexts<commit_after>var traverse = require("../../traverse");
var util     = require("../../util");
var t        = require("../../types");

exports.ClassDeclaration = function (node, parent, file, scope) {
  var closure = true;
  if (t.isProgram(parent) || t.isBlockStatement(parent)) {
    closure = false;
  }

  var newNode = new Class(node, file, scope, closure).run();
  if (closure) {
    // declaration in an expression context...
    // export default class Foo {}
    scope.push({
      kind: "var",
      key: node.id.key,
      id: node.id
    });
    return t.assignmentExpression("=", node.id, newNode);
  } else {
    return newNode;
  }
};

exports.ClassExpression = function (node, parent, file, scope) {
  return new Class(node, file, scope, true).run();
};

/**
 * Description
 *
 * @param {Node} node
 * @param {File} file
 * @param {Scope} scope
 * @param {Boolean} closure
 */

function Class(node, file, scope, closure) {
  this.closure = closure;
  this.scope   = scope;
  this.node    = node;
  this.file    = file;

  this.hasInstanceMutators = false;
  this.hasStaticMutators   = false;

  this.instanceMutatorMap = {};
  this.staticMutatorMap   = {};
  this.hasConstructor     = false;
  this.className          = node.id || file.generateUidIdentifier("class", scope);
{'fraction_non_alphanumeric': 0.15735641227380015, 'fraction_numerical': 0.0, 'mean_word_length': 3.1016129032258064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3102294', 'n_tokens_mistral': 799, 'n_tokens_neox': 788, 'n_words': 198}