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

Code before:
        default:
          shouldPrintParens = true;
      }
    }

    let indentParenthesized = false;
    if (
      !shouldPrintParens &&
      this._noLineTerminator &&
      (node.leadingComments?.some(commentIsNewline) ||
        (this.format.retainLines &&
          node.loc &&
          node.loc.start.line > this._buf.getCurrentLine()))
    ) {
      shouldPrintParens = true;
      indentParenthesized = true;
    }

    let oldNoLineTerminatorAfterNode;
    let oldTokenContext;
    if (!shouldPrintParens) {
      noLineTerminatorAfter ||=
        (parent &&
          this._noLineTerminatorAfterNode === parent &&
          n.isLastChild(parent, node)) ||
        false;
      if (noLineTerminatorAfter) {
        if (node.trailingComments?.some(commentIsNewline)) {
          if (isExpression(node)) shouldPrintParens = true;
        } else {
          oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
          this._noLineTerminatorAfterNode = node;
        }
      }
    }

    if (shouldPrintParens) {
      this.token("(");
      if (indentParenthesized) this.indent();
      this._endsWithInnerRaw = false;
      if (this.tokenContext & TokenContext.forInOrInitHeadAccumulate) {
        oldTokenContext = this.tokenContext;
        this.tokenContext = TokenContext.normal;
      }
      oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
      this._noLineTerminatorAfterNode = null;
    }

    this._lastCommentLine = 0;

    this._printLeadingComments(node, parent);

Review comment (suggestion):

```suggestion
        !!parent &&
        this._noLineTerminatorAfterNode === parent &&
        n.isLastChild(parent, node)
```

Code after:
        default:
          shouldPrintParens = true;
      }
    }

    let indentParenthesized = false;
    if (
      !shouldPrintParens &&
      this._noLineTerminator &&
      (node.leadingComments?.some(commentIsNewline) ||
        (this.format.retainLines &&
          node.loc &&
          node.loc.start.line > this._buf.getCurrentLine()))
    ) {
      shouldPrintParens = true;
      indentParenthesized = true;
    }

    let oldNoLineTerminatorAfterNode;
    let oldTokenContext;
    if (!shouldPrintParens) {
      noLineTerminatorAfter ||=
        !!parent &&
        this._noLineTerminatorAfterNode === parent &&
        n.isLastChild(parent, node);
      if (noLineTerminatorAfter) {
        if (node.trailingComments?.some(commentIsNewline)) {
          if (isExpression(node)) shouldPrintParens = true;
        } else {
          oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
          this._noLineTerminatorAfterNode = node;
        }
      }
    }

    if (shouldPrintParens) {
      this.token("(");
      if (indentParenthesized) this.indent();
      this._endsWithInnerRaw = false;
      if (this.tokenContext & TokenContext.forInOrInitHeadAccumulate) {
        oldTokenContext = this.tokenContext;
        this.tokenContext = TokenContext.normal;
      }
      oldNoLineTerminatorAfterNode = this._noLineTerminatorAfterNode;
      this._noLineTerminatorAfterNode = null;
    }

    this._lastCommentLine = 0;

    this._printLeadingComments(node, parent);