Skip to content

Unstable binary expressions format #7746

@fisker

Description

@fisker

Prettier 1.19.1
Playground link

--parser babel

Input:

function binaryInBinaryLeft() {
  return (
    // Reason for 42
    42
  ) * 84 + 2
}

function binaryInBinaryRight() {
  return (
    // Reason for 42
    42
  ) + 84 * 2
}

function conditional() {
  return (
    // Reason for 42
    42
  ) ? 1 : 2
}

function binaryInConditional() {
  return (
    // Reason for 42
    42
  ) * 3 ? 1 : 2
}

Output:

function binaryInBinaryLeft() {
  return (
    // Reason for 42
    42 *
      84 +
    2
  );
}

function binaryInBinaryRight() {
  return (
    // Reason for 42
    42 +
    84 * 2
  );
}

function conditional() {
  return (
    // Reason for 42
    42
      ? 1
      : 2
  );
}

function binaryInConditional() {
  return (
    // Reason for 42
    42 * 3
      ? 1
      : 2
  );
}

Second Output:

function binaryInBinaryLeft() {
  return (
    // Reason for 42
    42 * 84 + 2
  );
}

function binaryInBinaryRight() {
  return (
    // Reason for 42
    42 + 84 * 2
  );
}

function conditional() {
  return (
    // Reason for 42
    42 ? 1 : 2
  );
}

function binaryInConditional() {
  return (
    // Reason for 42
    42 * 3 ? 1 : 2
  );
}

Expected behavior:

Second output should not change


Issue found in #7565 , tests in file https://github.com/prettier/prettier/blob/next/tests/comments/return-statement.js

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions