Repository: babel/babel
File: packages/babel-traverse/src/scope/index.ts (TypeScript)

Code before:
    case "JSXOpeningElement":
      gatherNodeParts(node.name, parts);
      break;

    case "JSXFragment":
      gatherNodeParts(node.openingFragment, parts);
      break;

    case "JSXOpeningFragment":
      parts.push("Fragment");
      break;

    case "JSXNamespacedName":
      gatherNodeParts(node.namespace, parts);
      gatherNodeParts(node.name, parts);
      break;
  }
}

function resetScope(scope: Scope) {
  scope.references = Object.create(null);
  scope.bindings = Object.create(null);
  scope.globals = Object.create(null);
  scope.uids = Object.create(null);
  scope.data = Object.create(null);
}

interface CollectVisitorState {
  assignments: NodePath<t.AssignmentExpression>[];
  references: NodePath<t.Identifier | t.JSXIdentifier>[];
  constantViolations: NodePath[];
}

const collectorVisitor: Visitor<CollectVisitorState> = {
  ForStatement(path) {
    const declar = path.get("init");
    // delegate block scope handling to the `BlockScoped` method
    if (declar.isVar()) {
      const { scope } = path;
      const parentScope = scope.getFunctionParent() || scope.getProgramParent();
      parentScope.registerBinding("var", declar);
    }
  },

  Declaration(path) {
    // delegate block scope handling to the `BlockScoped` method
    if (path.isBlockScoped()) return;

    // delegate import handing to the `ImportDeclaration` method
    if (path.isImportDeclaration()) return;


Review comment (refactor):
This helper seems to be a genuine scope method, I think it could be public as well since the `scope.data` is user defined: They might want to override the `resetScope` method to do custom data cleanup.

Code after:
    case "JSXOpeningElement":
      gatherNodeParts(node.name, parts);
      break;

    case "JSXFragment":
      gatherNodeParts(node.openingFragment, parts);
      break;

    case "JSXOpeningFragment":
      parts.push("Fragment");
      break;

    case "JSXNamespacedName":
      gatherNodeParts(node.namespace, parts);
      gatherNodeParts(node.name, parts);
      break;
  }
}

function resetScope(scope: Scope) {
  scope.references = Object.create(null);
  scope.bindings = Object.create(null);
  scope.globals = Object.create(null);
  scope.uids = Object.create(null);
}

interface CollectVisitorState {
  assignments: NodePath<t.AssignmentExpression>[];
  references: NodePath<t.Identifier | t.JSXIdentifier>[];
  constantViolations: NodePath[];
}

const collectorVisitor: Visitor<CollectVisitorState> = {
  ForStatement(path) {
    const declar = path.get("init");
    // delegate block scope handling to the `BlockScoped` method
    if (declar.isVar()) {
      const { scope } = path;
      const parentScope = scope.getFunctionParent() || scope.getProgramParent();
      parentScope.registerBinding("var", declar);
    }
  },

  Declaration(path) {
    // delegate block scope handling to the `BlockScoped` method
    if (path.isBlockScoped()) return;

    // delegate import handing to the `ImportDeclaration` method
    if (path.isImportDeclaration()) return;

    // this will be hit again once we traverse into it after this iteration