<commit_before>import traverser from '../traverser';
import TemplateLiteral from './../syntax/TemplateLiteral';
import TemplateElement from './../syntax/TemplateElement';
import isString from './../utils/isString';
import _ from 'lodash';

export default function(ast) {
  traverser.replace(ast, {
    enter(node) {
      if (isPlusExpression(node)) {
        this.skip();

        const [operands, isStringConcatenation] = flattenPlusExpression(node);

        if (isStringConcatenation && !operands.every(isString)) {
          const literal = new TemplateLiteral(splitQuasisAndExpressions(operands));
          literal.comments = operands.comments;
          return literal;
        }
      }
    }
  });
}

// Returns two items:
// - flat array of all the plus operation sub-expressions
// - true when the result of the plus operation is a string
function flattenPlusExpression(node) {
  if (isPlusExpression(node)) {
    const [left, leftIsString] = flattenPlusExpression(node.left);
    const [right, rightIsString] = flattenPlusExpression(node.right);

    if (leftIsString || rightIsString) {
      const operands = _.flatten([left, right]);
      operands.comments = _.flatten([
        node.comments || [],
        left.comments || [],
        right.comments || []
      ]);
      return [operands, true];
    }
    else {
      return [node, false];
    }
  }
  else {
    return [node, isString(node)];
  }
}

function isPlusExpression(node) {
  return node.type === 'BinaryExpression' && node.operator === '+';
}

function splitQuasisAndExpressions(operands) {
  const quasis = [];
  const expressions = [];

  for (let i = 0; i < operands.length; i++) {
    const curr = operands[i];

    if (isString(curr)) {
      let currVal = curr.value;
      let currRaw = escapeForTemplate(curr.raw);

      while (isString(operands[i + 1] || {})) {<commit_msg>Do not attach comments property to array<commit_after>import traverser from '../traverser';
import TemplateLiteral from './../syntax/TemplateLiteral';
import TemplateElement from './../syntax/TemplateElement';
import isString from './../utils/isString';
import _ from 'lodash';

export default function(ast) {
  traverser.replace(ast, {
    enter(node) {
      if (isPlusExpression(node)) {
        this.skip();

        const [operands, isStringConcatenation, comments] = flattenPlusExpression(node);

        if (isStringConcatenation && !operands.every(isString)) {
          const literal = new TemplateLiteral(splitQuasisAndExpressions(operands));
          literal.comments = comments;
          return literal;
        }
      }
    }
  });
}

// Returns three items:
// - flat array of all the plus operation sub-expressions
// - true when the result of the plus operation is a string
// - array of comments
function flattenPlusExpression(node) {
  if (isPlusExpression(node)) {
    const [left, leftIsString, leftComments] = flattenPlusExpression(node.left);
    const [right, rightIsString, rightComments] = flattenPlusExpression(node.right);

    if (leftIsString || rightIsString) {
      const operands = _.flatten([left, right]);
      const comments = _.flatten([
        node.comments || [],
        leftComments,
        rightComments
      ]);
      return [operands, true, comments];
    }
    else {
      return [node, false, node.comments || []];
    }
  }
  else {
    return [node, isString(node), node.comments || []];
  }
}

function isPlusExpression(node) {
  return node.type === 'BinaryExpression' && node.operator === '+';
}

function splitQuasisAndExpressions(operands) {
  const quasis = [];
  const expressions = [];

  for (let i = 0; i < operands.length; i++) {
    const curr = operands[i];

    if (isString(curr)) {
      let currVal = curr.value;
      let currRaw = escapeForTemplate(curr.raw);

      while (isString(operands[i + 1] || {})) {
{'fraction_non_alphanumeric': 0.13432060275396207, 'fraction_numerical': 0.0010392309690828788, 'mean_word_length': 3.0697674418604652, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6406266', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1118, 'n_words': 280}