Repository: babel/babel
File: packages/babel-generator/src/node/parentheses.ts (TypeScript)

Code before:
  node: t.BinaryExpression,
  parent: t.Node,
  tokenContext: unknown,
  inForStatementInit: boolean,
): boolean {
  // for ((1 in []);;);
  // for (var x = (1 in []) in 2);
  return node.operator === "in" && inForStatementInit;
}

export function SequenceExpression(
  node: t.SequenceExpression,
  parent: t.Node,
): boolean {
  const parentType = parent.type;
  if (
    parentType === "SequenceExpression" ||
    parentType === "ParenthesizedExpression" ||
    (parentType === "MemberExpression" && parent.property === node) ||
    (parentType === "OptionalMemberExpression" && parent.property === node) ||
    parentType === "TemplateLiteral"
  ) {
    return false;
  }
  if (parentType === "ClassDeclaration" || parentType === "ClassExpression") {
    return parent.superClass === node;
  }
  if (parentType === "ForOfStatement") {
    return parent.right === node;
  }

  return !isStatement(parent);
}

export function YieldExpression(
  node: t.YieldExpression,
  parent: t.Node,
): boolean {
  const parentType = parent.type;
  return (
    parentType === "BinaryExpression" ||
    parentType === "LogicalExpression" ||
    parentType === "UnaryExpression" ||
    parentType === "SpreadElement" ||
    hasPostfixPart(node, parent) ||
    (parentType === "AwaitExpression" && isYieldExpression(node)) ||
    (parentType === "ConditionalExpression" && node === parent.test) ||
    isClassExtendsClause(node, parent) ||
    isTSTypeExpression(parentType)
  );
}

Review comment (suggestion):
It seems to me that if a SequenceExpression is an immediate child of Class, it must be the superClass, since the other productions are wrapped within either class element or the Decorator node.

If that's the case, then the `ClassExpression` branch can also be removed as it is already covered by the last return. 

Code after:
  node: t.BinaryExpression,
  parent: t.Node,
  tokenContext: unknown,
  inForStatementInit: boolean,
): boolean {
  // for ((1 in []);;);
  // for (var x = (1 in []) in 2);
  return node.operator === "in" && inForStatementInit;
}

export function SequenceExpression(
  node: t.SequenceExpression,
  parent: t.Node,
): boolean {
  const parentType = parent.type;
  if (
    parentType === "SequenceExpression" ||
    parentType === "ParenthesizedExpression" ||
    (parentType === "MemberExpression" && parent.property === node) ||
    (parentType === "OptionalMemberExpression" && parent.property === node) ||
    parentType === "TemplateLiteral"
  ) {
    return false;
  }
  if (parentType === "ClassDeclaration") {
    return true;
  }
  if (parentType === "ForOfStatement") {
    return parent.right === node;
  }
  if (parentType === "ExportDefaultDeclaration") {
    return true;
  }

  return !isStatement(parent);
}

export function YieldExpression(
  node: t.YieldExpression,
  parent: t.Node,
): boolean {
  const parentType = parent.type;
  return (
    parentType === "BinaryExpression" ||
    parentType === "LogicalExpression" ||
    parentType === "UnaryExpression" ||
    parentType === "SpreadElement" ||
    hasPostfixPart(node, parent) ||
    (parentType === "AwaitExpression" && isYieldExpression(node)) ||
    (parentType === "ConditionalExpression" && node === parent.test) ||
    isClassExtendsClause(node, parent) ||