<commit_before>'use strict';

module.exports = ({ Plugin, types: t }) => {
  const VOID_0 = t.unaryExpression('void', t.numericLiteral(0), true);
  const seen = Symbol('seen');

  return {
    visitor: {
      // undefined -> void 0
      ReferencedIdentifier(path) {
        if (path.node.name === 'undefined') {
          path.replaceWith(VOID_0);
        }
      },

      // { 'foo': 'bar' } -> { foo: 'bar' }
      Property: {
        exit({ node }) {
          let key = node.key;
          if (!t.isLiteral(key)) {
            return;
          }

          if (key.value.match(/^\d+$/)) {
            node.key = t.numericLiteral(parseInt(node.key.value, 10));
            node.computed = false;
          } else if (t.isValidIdentifier(key.value)) {
            node.key = t.identifier(key.value);
            node.computed = false;
          }
        },
      },

      // foo['bar'] -> foo.bar
      MemberExpression: {
        exit({ node }) {
          let prop = node.property;
          if (!node.computed || !t.isLiteral(prop)) {
            return;
          }

          if (prop.value.match(/^\d+$/)) {
            node.property = t.numericLiteral(parseInt(prop.value, 10));
            node.computed = false;
          } else if (t.isValidIdentifier(prop.value)) {
            node.property = t.identifier(prop.value);
            node.computed = false;
          }
        },
      },

      CallExpression(path) {
        const { node } = path;

        // Number(foo) -> +foo
        if (t.isIdentifier(node.callee, { name: 'Number' }) &&
          node.arguments.length === 1) {
          path.replaceWith(t.unaryExpression('+', node.arguments[0], true));
          return;
        }

        // String(foo) -> foo + ''
        if (t.isIdentifier(node.callee, { name: 'String' }) &&
          node.arguments.length === 1) {
          path.replaceWith(t.binaryExpression('+', node.arguments[0], t.stringLiteral('')));
          return;
        }
<commit_msg>Just check string literal<commit_after>'use strict';

module.exports = ({ Plugin, types: t }) => {
  const VOID_0 = t.unaryExpression('void', t.numericLiteral(0), true);
  const seen = Symbol('seen');

  return {
    visitor: {
      // undefined -> void 0
      ReferencedIdentifier(path) {
        if (path.node.name === 'undefined') {
          path.replaceWith(VOID_0);
        }
      },

      // { 'foo': 'bar' } -> { foo: 'bar' }
      Property: {
        exit({ node }) {
          let key = node.key;
          if (!t.isStringLiteral(key)) {
            return;
          }

          if (key.value.match(/^\d+$/)) {
            node.key = t.numericLiteral(parseInt(node.key.value, 10));
            node.computed = false;
          } else if (t.isValidIdentifier(key.value)) {
            node.key = t.identifier(key.value);
            node.computed = false;
          }
        },
      },

      // foo['bar'] -> foo.bar
      MemberExpression: {
        exit({ node }) {
          let prop = node.property;
          if (!node.computed || !t.isStringLiteral(prop)) {
            return;
          }

          if (prop.value.match(/^\d+$/)) {
            node.property = t.numericLiteral(parseInt(prop.value, 10));
            node.computed = false;
          } else if (t.isValidIdentifier(prop.value)) {
            node.property = t.identifier(prop.value);
            node.computed = false;
          }
        },
      },

      CallExpression(path) {
        const { node } = path;

        // Number(foo) -> +foo
        if (t.isIdentifier(node.callee, { name: 'Number' }) &&
          node.arguments.length === 1) {
          path.replaceWith(t.unaryExpression('+', node.arguments[0], true));
          return;
        }

        // String(foo) -> foo + ''
        if (t.isIdentifier(node.callee, { name: 'String' }) &&
          node.arguments.length === 1) {
          path.replaceWith(t.binaryExpression('+', node.arguments[0], t.stringLiteral('')));
          return;
        }

{'fraction_non_alphanumeric': 0.16557952834922227, 'fraction_numerical': 0.006021073758153537, 'mean_word_length': 1.6509308510638299, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3282310', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1193, 'n_words': 213}