<commit_before>import * as messages from "../../messages";
import traverse from "../../traversal";
import extend from "lodash/object/extend";
import object from "../../helpers/object";
import * as util from  "../../util";
import * as t from "../../types";

var remapVisitor = {
  enter(node, parent, scope, formatter) {
    var remap = formatter.internalRemap[node.name];
    if (this.isReferencedIdentifier() && remap) {
      if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
        return remap;
      }
    }

    if (t.isUpdateExpression(node)) {
      var exported = formatter.getExport(node.argument, scope);

      if (exported) {
        this.skip();

        // expand to long file assignment expression
        var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));

        // remap this assignment expression
        var remapped = formatter.remapExportAssignment(assign, exported);

        // we don't need to change the result
        if (t.isExpressionStatement(parent) || node.prefix) {
          return remapped;
        }

        var nodes = [];
        nodes.push(remapped);

        var operator;
        if (node.operator === "--") {
          operator = "+";
        } else { // "++"
          operator = "-";
        }
        nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));

        return t.sequenceExpression(nodes);
      }
    }

    if (node._skipModulesRemap) {
      return this.skip();
    }

    if (t.isAssignmentExpression(node) && !node._ignoreModulesRemap) {
      var exported = formatter.getExport(node.left, scope);
      if (exported) {
        this.skip();
        return formatter.remapExportAssignment(node, exported);
      }
    }
  }
};

var importsVisitor = {
  ImportDeclaration: {
    enter(node, parent, scope, formatter) {
      formatter.hasLocalImports = true;
      extend(formatter.localImports, this.getBindingIdentifiers());
    }
  }
};

var exportsVisitor = traverse.explode({
  ExportDeclaration: {
    enter(node, parent, scope, formatter) {
      formatter.hasLocalExports = true;

      var declar = this.get("declaration");
      if (declar.isStatement()) {
        var bindings = declar.getBindingIdentifiers()
        for (var name in bindings) {
          var binding = bindings[name];
          formatter._addExport(name, binding);
        }
      }
<commit_msg>move export reassignment to exit handler - fixes #1255<commit_after>import * as messages from "../../messages";
import traverse from "../../traversal";
import extend from "lodash/object/extend";
import object from "../../helpers/object";
import * as util from  "../../util";
import * as t from "../../types";

var remapVisitor = {
  enter(node, parent, scope, formatter) {
    var remap = formatter.internalRemap[node.name];
    if (this.isReferencedIdentifier() && remap) {
      if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
        return remap;
      }
    }

    if (t.isUpdateExpression(node)) {
      var exported = formatter.getExport(node.argument, scope);

      if (exported) {
        this.skip();

        // expand to long file assignment expression
        var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));

        // remap this assignment expression
        var remapped = formatter.remapExportAssignment(assign, exported);

        // we don't need to change the result
        if (t.isExpressionStatement(parent) || node.prefix) {
          return remapped;
        }

        var nodes = [];
        nodes.push(remapped);

        var operator;
        if (node.operator === "--") {
          operator = "+";
        } else { // "++"
          operator = "-";
        }
        nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));

        return t.sequenceExpression(nodes);
      }
    }

    if (node._skipModulesRemap) {
      return this.skip();
    }
  },

  exit(node, parent, scope, formatter) {
    if (t.isAssignmentExpression(node) && !node._ignoreModulesRemap) {
      var exported = formatter.getExport(node.left, scope);
      if (exported) {
        return formatter.remapExportAssignment(node, exported);
      }
    }
  }
};

var importsVisitor = {
  ImportDeclaration: {
    enter(node, parent, scope, formatter) {
      formatter.hasLocalImports = true;
      extend(formatter.localImports, this.getBindingIdentifiers());
    }
  }
};

var exportsVisitor = traverse.explode({
  ExportDeclaration: {
    enter(node, parent, scope, formatter) {
      formatter.hasLocalExports = true;

      var declar = this.get("declaration");
      if (declar.isStatement()) {
        var bindings = declar.getBindingIdentifiers()
        for (var name in bindings) {
          var binding = bindings[name];
          formatter._addExport(name, binding);
        }
      }

{'fraction_non_alphanumeric': 0.13568847852268165, 'fraction_numerical': 0.002007226013649137, 'mean_word_length': 2.51410437235543, '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': '7381966', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1424, 'n_words': 322}