Repository: prettier/prettier
File: src/language-js/parse/postprocess/index.js (JavaScript)

Code before:

      followingComment = comment;
    }
  }

  ast = visitNode(ast, (node) => {
    switch (node.type) {
      case "ParenthesizedExpression": {
        const { expression } = node;

        // Align range with `flow`
        if (expression.type === "TypeCastExpression") {
          expression.range = [...node.range];
          return expression;
        }

        // Keep ParenthesizedExpression nodes only if they have Closure-style type cast comments.
        const previousComment = ast.comments.findLast(
          (comment) => locEnd(comment) <= locStart(node),
        );
        const keepTypeCast =
          previousComment !== undefined &&
          isTypeCastComment(previousComment) &&
          // check that there are only white spaces between the comment and the parenthesis
          text.slice(locEnd(previousComment), locStart(node)).trim().length ===
            0;

        if (!keepTypeCast) {
          expression.extra = { ...expression.extra, parenthesized: true };
          return expression;
        }
        break;
      }

      case "LogicalExpression":
        // We remove unneeded parens around same-operator LogicalExpressions
        if (isUnbalancedLogicalTree(node)) {
          return rebalanceLogicalTree(node);
        }
        break;

      case "TemplateElement":
        // `flow` and `typescript` follows the `espree` style positions
        // https://github.com/eslint/js/blob/5826877f7b33548e5ba984878dd4a8eac8448f87/packages/espree/lib/espree.js#L213
        if (
          parser === "flow" ||
          parser === "espree" ||
          parser === "typescript"
        ) {
          const start = locStart(node) + 1;
          const end = locEnd(node) - (node.tail ? 1 : 2);

Review comment (suggestion):
```suggestion
          !/\S/.test(text.slice(locEnd(previousComment), locStart(node)))
```

Code after:
      }

      followingComment = comment;
    }
  }

  ast = visitNode(ast, (node) => {
    switch (node.type) {
      case "ParenthesizedExpression": {
        const { expression } = node;

        // Align range with `flow`
        if (expression.type === "TypeCastExpression") {
          expression.range = [...node.range];
          return expression;
        }

        // Keep ParenthesizedExpression nodes only if they have Closure-style type cast comments.
        const nodeStart = locStart(node);
        const previousComment = ast.comments.findLast(
          (comment) => locEnd(comment) <= nodeStart,
        );
        const keepTypeCast =
          previousComment &&
          isTypeCastComment(previousComment) &&
          // check that there are only white spaces between the comment and the parenthesis
          text.slice(locEnd(previousComment), nodeStart).trim().length === 0;

        if (!keepTypeCast) {
          expression.extra = { ...expression.extra, parenthesized: true };
          return expression;
        }
        break;
      }

      case "LogicalExpression":
        // We remove unneeded parens around same-operator LogicalExpressions
        if (isUnbalancedLogicalTree(node)) {
          return rebalanceLogicalTree(node);
        }
        break;

      case "TemplateElement":
        // `flow` and `typescript` follows the `espree` style positions
        // https://github.com/eslint/js/blob/5826877f7b33548e5ba984878dd4a8eac8448f87/packages/espree/lib/espree.js#L213
        if (
          parser === "flow" ||
          parser === "espree" ||
          parser === "typescript"
        ) {
          const start = locStart(node) + 1;