Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty lines unexpectedly removed in JSX #3953

Open
k15a opened this issue Feb 12, 2018 · 2 comments
Open

Empty lines unexpectedly removed in JSX #3953

k15a opened this issue Feb 12, 2018 · 2 comments
Labels
lang:jsx Issues affecting JSX (not general JS issues) type:bug Issues identifying ugly output, or a defect in the program

Comments

@k15a
Copy link
Collaborator

k15a commented Feb 12, 2018

I am not really sure when this happens but the as you can see in the first example all the additional line break are reduced to one and in the second example the line breaks are completely removed.

Prettier 1.10.2
Playground link

Input:

const children = ({ data, paginationProps }) => (
  <div>
    <p>
      {paginationProps.currentPage} / {paginationProps.totalPages}
    </p>

    <input
      type="number"
      id="specificPage"
      onChange={(event) =>
        paginationProps.goToPage(parseInt(event.target.value, 10))
      }
    />
  </div>
);

const children = ({ data, paginationProps }) => (
  <div>
    {paginationProps.currentPage} / {paginationProps.totalPages}

    <input
      type="number"
      id="specificPage"
      onChange={(event) =>
        paginationProps.goToPage(parseInt(event.target.value, 10))
      }
    />
  </div>
);

Output:

const children = ({ data, paginationProps }) => (
  <div>
    <p>
      {paginationProps.currentPage} / {paginationProps.totalPages}
    </p>

    <input
      type="number"
      id="specificPage"
      onChange={event =>
        paginationProps.goToPage(parseInt(event.target.value, 10))
      }
    />
  </div>
);

const children = ({ data, paginationProps }) => (
  <div>
    {paginationProps.currentPage} / {paginationProps.totalPages}
    <input
      type="number"
      id="specificPage"
      onChange={event =>
        paginationProps.goToPage(parseInt(event.target.value, 10))
      }
    />
  </div>
);

Expected behavior:
I would expect that both cases behave the same way.

@j-f1
Copy link
Member

j-f1 commented Feb 12, 2018

Babel doesn‘t seem to care about any of the whitespace that’s changed. I guess this is “just” a stylistic thing.

@j-f1 j-f1 added status:needs discussion Issues needing discussion and a decision to be made before action can be taken lang:jsx Issues affecting JSX (not general JS issues) labels Feb 12, 2018
@thorn0 thorn0 changed the title JSX line break normalization inconsistent Empty lines unexpectedly removed in JSX May 26, 2020
@thorn0 thorn0 added type:bug Issues identifying ugly output, or a defect in the program and removed status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels May 26, 2020
@phil-lgr
Copy link

I think this only happen IF there is a naked statement in JSX

image

Without the naked {paginationProps.currentPage} / {paginationProps.totalPages}, the empty lines are preserved

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang:jsx Issues affecting JSX (not general JS issues) type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

4 participants