Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

fix: do not print > on new line #678

Merged
merged 6 commits into from
Oct 15, 2022
Merged

Conversation

ah-yu
Copy link
Contributor

@ah-yu ah-yu commented Oct 14, 2022

Closes #675

@cristianoc
Copy link
Contributor

@cknitt could you try on your codebase to check no formatting change?

@@ -3978,6 +3978,38 @@ and printPexpApply ~customLayout expr cmtTbl =

and printJsxExpression ~customLayout lident args cmtTbl =
let name = printJsxName lident in
let hasTailSingleLineComment =
Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to traverse the props multiple times. Do we fuse this logic with printJsxProps? There we walk the props one by one. We eventually arrive at the children, so we have all information inside printJsxProps, don't we?

printJsxProps also seems like a good place to try and print the closing >. What do you think of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense to me. Will take a look later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We better not print > in the printJsxProps function, because we have additional logic to determine whether the tag is self-closing, and then choose to print (> and </A>) or />

@cknitt
Copy link
Member

cknitt commented Oct 14, 2022

@cknitt could you try on your codebase to check no formatting change?

Yes, will test later today. But as the formatting in the test results is back to what it was before, I think we should be good.

@cknitt
Copy link
Member

cknitt commented Oct 14, 2022

I can confirm that the formatting is back to what it was before. At least as far as JSX is concerned. I had one other formatting change:

module PipeFirst = {

}

=>

module PipeFirst = {}

that must have been caused by some other commit. But this will occur rarely in practice (and is definitely an improvement IMHO).

@ah-yu
Copy link
Contributor Author

ah-yu commented Oct 15, 2022

Self-closing tags and normal tags have different formatting behavior. We always put /> on a new line

<A 
 a=""
/>

<A 
 a="1">
 <B />
</A>

Should we keep them consistent?

@cknitt
Copy link
Member

cknitt commented Oct 15, 2022

I cannot confirm that. I just tried again with the version I tested yesterday and with 10.0.1 in the playground, and I am getting

<A a="" />

<A a="1">
  <B />
</A>

@ah-yu
Copy link
Contributor Author

ah-yu commented Oct 15, 2022

<A 
// break tag
 a=""
/>

<A 
// break tag
 a="1">
 <B />
</A>

Try this?
@cknitt

@cknitt
Copy link
Member

cknitt commented Oct 15, 2022

Ah, right, yes, this does give me

<A
// break tag
  a=""
/>

<A
// break tag
  a="1">
  <B />
</A>

in the playground.

@ah-yu
Copy link
Contributor Author

ah-yu commented Oct 15, 2022

Should we keep them consistent?

@cknitt
Copy link
Member

cknitt commented Oct 15, 2022

IMHO, in 10.1, we should avoid any format changes. We can make things consistent in 11.0 (always keep the > or /> on the same line or always put it on the next - to be discussed).

What do you think @cristianoc?

@cristianoc
Copy link
Contributor

Yes I think avoiding changes is best for 10.1.

@ah-yu ah-yu marked this pull request as ready for review October 15, 2022 08:07
@cristianoc
Copy link
Contributor

@ah-yu is this ready to go, or is there more to do?

@ah-yu
Copy link
Contributor Author

ah-yu commented Oct 15, 2022

This is ready to go @cristianoc

Wait a minute, I need more test

@ah-yu
Copy link
Contributor Author

ah-yu commented Oct 15, 2022

I think this is ready to go @cristianoc

@cristianoc cristianoc merged commit b9f2f7b into rescript-lang:master Oct 15, 2022
@ah-yu ah-yu deleted the patch-1 branch October 15, 2022 15:17
ah-yu added a commit to ah-yu/syntax that referenced this pull request Oct 15, 2022
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.

Unnecessary format changes in JSX between 10.0.1 and 10.1.0-rc.1
4 participants