<commit_before>'use strict';

var _ = require('lodash');
var j = require('junify');
var esprima = require('esprima');

var extensions = require('./extensions');

function expressionsOf(ast, binding) {
  return declarationsOf(ast).concatMap(function (node) {
    if (j.unify({ type: 'FunctionDeclaration', id: identifier(binding), _: j._ }, node)) {
      return [node.body];
    } else if (j.unify({ type: 'VariableDeclarator', id: identifier(binding), _: j._ }, node)) {
      return [node.init];
    } else {
      return [];
    }
  });
}

function expressionHasUsage(arg, target) {
  return matches(arg, [
    [{ type: 'CallExpression', callee: j.variable('sub'), _: j._ }, function (result) {
      return expressionHasUsage(result.sub, target);
    }],
    [{ type: 'BinaryExpression', operator: j._, left: j.variable('sub1'), right: j.variable('sub2') }, function (result) {
      return expressionHasUsage(result.sub1, target) || expressionHasUsage(result.sub2, target);
    }],
    [{ type: 'ReturnStatement', argument: j.variable('sub'), _: j._ }, function (result) {
      return expressionHasUsage(result.sub, target);
    }],
    [{ type: 'ExpressionStatement', expression: j.variable('sub'), _: j._ }, function (result) {
      return expressionHasUsage(result.sub, target);
    }],
    [{ type: 'BlockStatement', body: j.variable('sub'), _: j._ }, function (result) {
      return result.sub.some(function (it) {
        return expressionHasUsage(it, target);
      });
    }],
    [{ type: 'VariableDeclaration', declarations: j.variable('sub'), _: j._ }, function (result) {
      return result.sub.some(function (it) {
        return expressionHasUsage(it, target);
      });
    }],
    [{ type: 'VariableDeclarator', init: j.variable('sub'), _: j._ }, function (result) {
      return expressionHasUsage(result.sub, target);
    }],
    [{ type: 'Identifier', name: j.variable('sub'), _: j._ }, function (result) {
      return result.sub === target;
    }],
    [j._, _.constant(false)],
  ]);
}

function match(patterns) {
  return function (it) {
    return patterns.some(function (pattern) {
      return  j.unify(pattern, it);
    });
  };
}

function identifier(binding) {
  return { type: 'Identifier', name: binding };
}<commit_msg>using constant(true) in identifier pattern<commit_after>'use strict';

var _ = require('lodash');
var j = require('junify');
var esprima = require('esprima');

var extensions = require('./extensions');

function expressionsOf(ast, binding) {
  return declarationsOf(ast).concatMap(function (node) {
    if (j.unify({ type: 'FunctionDeclaration', id: identifier(binding), _: j._ }, node)) {
      return [node.body];
    } else if (j.unify({ type: 'VariableDeclarator', id: identifier(binding), _: j._ }, node)) {
      return [node.init];
    } else {
      return [];
    }
  });
}

function expressionHasUsage(arg, target) {
  return matches(arg, [
    [{ type: 'CallExpression', callee: j.variable('sub'), _: j._ }, function (result) {
      return expressionHasUsage(result.sub, target);
    }],
    [{ type: 'BinaryExpression', operator: j._, left: j.variable('sub1'), right: j.variable('sub2') }, function (result) {
      return expressionHasUsage(result.sub1, target) || expressionHasUsage(result.sub2, target);
    }],
    [{ type: 'ReturnStatement', argument: j.variable('sub'), _: j._ }, function (result) {
      return expressionHasUsage(result.sub, target);
    }],
    [{ type: 'ExpressionStatement', expression: j.variable('sub'), _: j._ }, function (result) {
      return expressionHasUsage(result.sub, target);
    }],
    [{ type: 'BlockStatement', body: j.variable('sub'), _: j._ }, function (result) {
      return result.sub.some(function (it) {
        return expressionHasUsage(it, target);
      });
    }],
    [{ type: 'VariableDeclaration', declarations: j.variable('sub'), _: j._ }, function (result) {
      return result.sub.some(function (it) {
        return expressionHasUsage(it, target);
      });
    }],
    [{ type: 'VariableDeclarator', init: j.variable('sub'), _: j._ }, function (result) {
      return expressionHasUsage(result.sub, target);
    }],
    [ identifier(target), _.constant(true) ],
    [ j._, _.constant(false) ],
  ]);
}

function match(patterns) {
  return function (it) {
    return patterns.some(function (pattern) {
      return  j.unify(pattern, it);
    });
  };
}

function identifier(binding) {
  return { type: 'Identifier', name: binding };
}
{'fraction_non_alphanumeric': 0.1778125698948781, 'fraction_numerical': 0.0017893088794453142, 'mean_word_length': 3.643821391484943, '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': '2435866', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1353, 'n_words': 312}