-
Notifications
You must be signed in to change notification settings - Fork 428
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
Fix record field and jsx props punned when with attributes #2824
Open
pedrobslisboa
wants to merge
2
commits into
reasonml:master
Choose a base branch
from
pedrobslisboa:fix/record-attr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ _esybuild | |
_esyinstall | ||
_release | ||
_export/ | ||
|
||
# opam | ||
_opam/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2113,8 +2113,10 @@ let createFormatter () = | |
true | ||
| _ -> false | ||
|
||
let isPunnedJsxArg lbl ident = | ||
(not (isLongIdentWithDot ident.txt)) && Longident.last_exn ident.txt = lbl | ||
let isPunnedJsxArg lbl ident attr = | ||
(not (isLongIdentWithDot ident.txt)) | ||
&& Longident.last_exn ident.txt = lbl | ||
&& attr = [] | ||
|
||
let is_unit_pattern x = | ||
match x.ppat_desc with | ||
|
@@ -4330,7 +4332,8 @@ let createFormatter () = | |
PipeFirstTree.flastNode list) into a more convenient structure * | ||
that allows us to express the segments: "foo" "f(a, b)" "g(c, d)". | ||
* PipeFirstTree.t expresses those segments. * | ||
[{exp = foo; args = []}; {exp = f; args = [a; b]}; {exp = g; args = [c; d]}] | ||
[{exp = foo; args = []}; {exp = f; args = [a; b]}; {exp = g; args = | ||
[c; d]}] | ||
*) | ||
let rec parse acc = function | ||
| PipeFirstTree.Exp e :: PipeFirstTree.Args args :: xs -> | ||
|
@@ -4360,12 +4363,13 @@ let createFormatter () = | |
*) | ||
let (flatNodes : PipeFirstTree.flatT) = flatten ~uncurried [] e in | ||
(* Turn * [Exp foo; Exp f; Args [a; b]; Exp g; Args [c; d]] * into * | ||
[{exp = foo; args = []}; {exp = f; args = [a; b]}; {exp = g; args = [c; d]}] | ||
[{exp = foo; args = []}; {exp = f; args = [a; b]}; {exp = g; args = | ||
[c; d]}] | ||
*) | ||
let (pipetree : PipeFirstTree.t) = parse [] flatNodes in | ||
(* Turn * | ||
[{exp = foo; args = []}; {exp = f; args = [a; b]}; {exp = g; args = [c; d]}] | ||
* into * [foo; ->f(a, b); ->g(c, d)] | ||
[{exp = foo; args = []}; {exp = f; args = [a; b]}; {exp = g; args = | ||
[c; d]}] * into * [foo; ->f(a, b); ->g(c, d)] | ||
*) | ||
let pipeSegments = | ||
match pipetree with | ||
|
@@ -5239,7 +5243,8 @@ let createFormatter () = | |
let value_has_jsx = jsxAttrs != [] in | ||
let nextAttr = | ||
match expression.pexp_desc with | ||
| Pexp_ident ident when isPunnedJsxArg lbl ident -> | ||
| Pexp_ident ident | ||
when isPunnedJsxArg lbl ident expression.pexp_attributes -> | ||
makeList ~break:Layout.Never [ atom "?"; atom lbl ] | ||
| Pexp_construct _ when value_has_jsx -> | ||
label | ||
|
@@ -5260,7 +5265,9 @@ let createFormatter () = | |
let value_has_jsx = jsxAttrs != [] in | ||
let nextAttr = | ||
match expression.pexp_desc with | ||
| Pexp_ident ident when isPunnedJsxArg lbl ident -> atom lbl | ||
| Pexp_ident ident | ||
when isPunnedJsxArg lbl ident expression.pexp_attributes -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
atom lbl | ||
| _ when isJSXComponent expression -> | ||
label | ||
(atom (lbl ^ "=")) | ||
|
@@ -5614,25 +5621,19 @@ let createFormatter () = | |
let everythingButReturnVal = | ||
(* Because align_closing is set to false, you get: * * (Brackets[] | ||
inserted to show boundaries between open/close of pattern list) * | ||
let[firstThing | ||
* secondThing | ||
* thirdThing] | ||
* * It only wraps to indent four by coincidence: If the "opening" | ||
token was * longer, you'd get: * * | ||
letReallyLong[firstThing | ||
* secondThing | ||
* thirdThing] | ||
* * For curried let bindings, we stick the arrow in the *last* | ||
pattern: * | ||
let[firstThing | ||
* secondThing | ||
* thirdThing =>] | ||
* * But it could have just as easily been the "closing" token | ||
corresponding to * "let". This works because we have | ||
[align_closing = false]. The benefit of * shoving it in the last | ||
pattern, is that we can turn [align_closing = true] * and still | ||
have the arrow stuck to the last pattern (which is usually what | ||
we * want) (See modeTwo below). | ||
let[firstThing * secondThing * thirdThing] * * It only | ||
wraps to indent four by coincidence: If the "opening" token was * | ||
longer, you'd get: * * | ||
letReallyLong[firstThing * secondThing * | ||
thirdThing] * * For curried let bindings, we stick | ||
the arrow in the *last* pattern: * | ||
let[firstThing * secondThing * thirdThing =>] * * But it | ||
could have just as easily been the "closing" token corresponding | ||
to * "let". This works because we have [align_closing = false]. | ||
The benefit of * shoving it in the last pattern, is that we can | ||
turn [align_closing = true] * and still have the arrow stuck to | ||
the last pattern (which is usually what we * want) (See modeTwo | ||
below). | ||
*) | ||
match partitioning with | ||
| None when sweet -> | ||
|
@@ -5824,11 +5825,10 @@ let createFormatter () = | |
it becomes pretty printed as * let x:t =.... In the proposal, it is | ||
not impossible - it is only * impossible to preserve unnecessary | ||
parenthesis around the let binding. * * The one downside is that | ||
integrating with existing code that uses | ||
[let x = | ||
* (blah:typ)] in standard OCaml will be parsed as a | ||
Pexp_constraint. There * might be some lossiness (beyond parens) that | ||
occurs in the original OCaml * parser. | ||
integrating with existing code that uses [let x = * (blah:typ)] in | ||
standard OCaml will be parsed as a Pexp_constraint. There * might be | ||
some lossiness (beyond parens) that occurs in the original OCaml * | ||
parser. | ||
*) | ||
method locallyAbstractPolymorphicFunctionBinding | ||
|
@@ -7099,9 +7099,11 @@ let createFormatter () = | |
match e.pexp_desc, shouldPun, allowPunning with | ||
(* record value punning. Turns {foo: foo, bar: 1} into {foo, bar: 1} *) | ||
(* also turns {Foo.bar: bar, baz: 1} into {Foo.bar, baz: 1} *) | ||
(* don't turn {bar: [@foo] bar, baz: 1} into {bar, baz: 1} *) | ||
(* don't turn {bar: Foo.bar, baz: 1} into {bar, baz: 1}, naturally *) | ||
| Pexp_ident { txt = Lident value; _ }, true, true | ||
when Longident.last_exn li.txt = value -> | ||
when Longident.last_exn li.txt = value && e.pexp_attributes = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may need to partition attributes here too |
||
-> | ||
makeList (maybeQuoteFirstElem li []) | ||
(* Force breaks for nested records or mel.obj sugar | ||
* Example: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use
stdAttrs
from the call topartitionAttributes
above here.