<commit_before>// https://github.com/zenparsing/es-function-bind

import * as t from "../../../types";

export var metadata = {
  optional: true,
  stage: 0
};

function getTempId(scope) {
  var id = scope.path.getData("functionBind");
  if (id) return id;

  id = scope.generateTemp("context");
  return scope.path.setData("functionBind", id);
}

function getStaticContext(bind, scope) {
  if (bind.object) {
    return scope.isStatic(bind.object) && bind.object;
  } else {
    return scope.isStatic(bind.callee.object) && bind.callee.object;
  }
}

function inferBindContext(bind, scope) {
  var staticContext = getStaticContext(bind, scope);
  if (staticContext) return staticContext;

  var tempId = getTempId(scope);
  if (bind.object) {
    bind.callee = t.sequenceExpression([
      t.assignmentExpression("=", tempId, bind.object),
      bind.callee
    ]);
  } else {
    bind.callee.object = t.assignmentExpression("=", tempId, bind.callee.object);<commit_msg>simplify getStaticContext in es7.functionBind transformer - thanks @RReverser!<commit_after>// https://github.com/zenparsing/es-function-bind

import * as t from "../../../types";

export var metadata = {
  optional: true,
  stage: 0
};

function getTempId(scope) {
  var id = scope.path.getData("functionBind");
  if (id) return id;

  id = scope.generateTemp("context");
  return scope.path.setData("functionBind", id);
}

function getStaticContext(bind, scope) {
  var object = bind.object || bind.callee.object;
  return scope.isStatic(object) && object;
}

function inferBindContext(bind, scope) {
  var staticContext = getStaticContext(bind, scope);
  if (staticContext) return staticContext;

  var tempId = getTempId(scope);
  if (bind.object) {
    bind.callee = t.sequenceExpression([
      t.assignmentExpression("=", tempId, bind.object),
      bind.callee
    ]);
  } else {
    bind.callee.object = t.assignmentExpression("=", tempId, bind.callee.object);
{'fraction_non_alphanumeric': 0.14845360824742268, 'fraction_numerical': 0.0015463917525773195, 'mean_word_length': 3.951530612244898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5626445', 'n_tokens_mistral': 629, 'n_tokens_neox': 625, 'n_words': 137}