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

Vue: Fix format on self-closing and empty blocks #9055

Merged
merged 7 commits into from
Aug 26, 2020

Conversation

fisker
Copy link
Member

@fisker fisker commented Aug 25, 2020

#9052 (comment)

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@fisker fisker mentioned this pull request Aug 25, 2020
6 tasks
@fisker fisker marked this pull request as ready for review August 25, 2020 15:34
@fisker fisker changed the title Vue: Fix format on self closing blocks Vue: Fix format on self-closing blocks Aug 25, 2020
@fisker
Copy link
Member Author

fisker commented Aug 25, 2020

DO you guys think this is bug?

Prettier 2.1.0
Playground link

--parser vue

Input:

<custom lang="markdown"></custom>

Output:

<custom lang="markdown">

</custom>

@thorn0
Copy link
Member

thorn0 commented Aug 25, 2020

Yes, looks unexpected.

@sosukesuzuki
Copy link
Member

I agree with thorn0

},
{
name: "non-space",
code: '<custom lang="markdown">\n \u2005 \n</custom>'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one, html think it's not empty, and markdown will print to a empty Doc, how do I tell it's empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only child node is text consisting of whitespace only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
      "type": "concat",
      "parts": [
        {
          "type": "concat",
          "parts": [
            {
              "type": "fill",
              "parts": []
            }
          ]
        }
      ]
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using normalizeParts from doc-utils. You might want to improve it to handle an empty fill doc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the embed parser return ifBreak('foo', ''), we should not be able to know it's empty or not. Am I right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we first check if the content of the tag is empty or whitespace-only and skip the embedded parser if it is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, and it works, just feel something not right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to assume that reformatting an empty document should result in an empty document for any language.

@fisker fisker force-pushed the vue-void-element branch 2 times, most recently from f976c33 to b44f7e0 Compare August 25, 2020 16:04
@fisker fisker changed the title Vue: Fix format on self-closing blocks Vue: Fix format on self-closing and empty blocks Aug 25, 2020
@fisker
Copy link
Member Author

fisker commented Aug 25, 2020

Done

@fisker fisker merged commit ebe9e07 into prettier:master Aug 26, 2020
@fisker fisker deleted the vue-void-element branch August 26, 2020 03:19
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants