-
Notifications
You must be signed in to change notification settings - Fork 429
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
Preserve function body braces and distinguish open vs. X.() #1826
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,11 @@ let x = [@attrEverything] (true && false); | |
/** | ||
* How attribute parsings respond to other syntactic constructs. | ||
*/ | ||
let add = a => [@onRet] a; | ||
let add = a => | ||
[@onRet] | ||
{ | ||
a; | ||
}; | ||
|
||
let add = a => [@onRet] a; | ||
|
||
|
@@ -382,8 +386,18 @@ type classAttributesOnKeys = { | |
. | ||
[@bs.set] key1: string, | ||
/* The follow two are the same */ | ||
[@bs.get null] key2: [@onType2] Js.t(int), | ||
[@bs.get null] key3: [@onType2] Js.t(int), | ||
[@bs.get | ||
{ | ||
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. What's happening here then? 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. The same thing. The attributes were specified with braces, and before this diff they were getting 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. Does that mean these will always get formatted like this now or something? 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. If you remove the braces I guess they will get formatted how they were previously. 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. Exactly. Previously, the braces were getting formatted away. Now, we preserve whether or not you included additional braces. You can have it format whichever way you want - and it will preserve your intent. |
||
null; | ||
} | ||
] | ||
key2: [@onType2] Js.t(int), | ||
[@bs.get | ||
{ | ||
null; | ||
} | ||
] | ||
key3: [@onType2] Js.t(int), | ||
key4: Js.t([@justOnInt] int), | ||
}; | ||
|
||
|
@@ -533,7 +547,13 @@ let res = | |
|
||
let res = | ||
switch (x) { | ||
| _ => [@attr] String.(Array.(concat)) | ||
| _ => | ||
[@attr] | ||
{ | ||
open String; | ||
open Array; | ||
concat; | ||
} | ||
}; | ||
|
||
/* GADT */ | ||
|
@@ -602,10 +622,6 @@ type tttttt = { | |
mutable x: int, | ||
}; | ||
|
||
let tmp = | ||
/** On if statement */ | ||
(if (true) {true} else {false}); | ||
|
||
type foo = | ||
option( | ||
[@foo | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
let preserveThis = "preserveThis"; | ||
|
||
let x = a => { | ||
preserveThis; | ||
}; | ||
|
||
let x = a => { | ||
/* Even with comment */ | ||
preserveThis; | ||
}; | ||
|
||
let res = { | ||
/** | ||
* doc comment. | ||
*/ | ||
(if (true) {()} else {()}); | ||
(); | ||
}; | ||
|
||
let x = a => { | ||
/* It would be okay for this comment to get formatted into | ||
* the braces but ideally it wouldn't. */ | ||
preserveThis; | ||
}; | ||
|
||
type recordType = { | ||
recordTypeFieldOne: int, | ||
recordTypeFieldTwo: string, | ||
}; | ||
|
||
let x = | ||
{ | ||
recordTypeFieldOne: 0, | ||
recordTypeFieldTwo: "two", | ||
}.recordTypeFieldOne; | ||
|
||
/** | ||
* Use a pointless wrapping. | ||
*/ | ||
let x = | ||
{ | ||
{ | ||
recordTypeFieldOne: 0, | ||
recordTypeFieldTwo: "two", | ||
}; | ||
}.recordTypeFieldOne; | ||
|
||
let createRecord = () => { | ||
recordTypeFieldOne: 0, | ||
recordTypeFieldTwo: "two", | ||
}; | ||
|
||
let x = | ||
{ | ||
createRecord(); | ||
}.recordTypeFieldOne; | ||
|
||
let y = [@attr] 3; | ||
|
||
/* The attribute on the explicit braces should also be preserved */ | ||
let y = | ||
[@attr] | ||
{ | ||
3; | ||
}; | ||
|
||
let myFun = (. a, b, c) => a + b + c; | ||
|
||
let result = { | ||
myFun(. 0, 1, 2); | ||
}; | ||
|
||
let result = | ||
[@attr] | ||
{ | ||
myFun(. 0, 1, 2); | ||
}; | ||
|
||
let tmp = | ||
/** On if statement */ | ||
{ | ||
if (true) {true} else {false}; | ||
}; | ||
|
||
let tmp = { | ||
let tmp = false; | ||
/** On if statement */ | ||
(if (tmp) {true} else {false}); | ||
}; | ||
|
||
let tmp = { | ||
let tmp = false; | ||
/** On if statement */ | ||
(if (tmp) {"true"} else {"false"}); | ||
"but the if statement wasn't the last"; | ||
}; | ||
|
||
module Callbacks = { | ||
let runThisCallback = (s, next) => { | ||
s ++ next("!"); | ||
(); | ||
}; | ||
}; | ||
|
||
let result = | ||
Callbacks.runThisCallback("hi", s => | ||
s ++ "concatThis!" | ||
); | ||
|
||
let result = | ||
Callbacks.runThisCallback("hi", s => { | ||
s ++ "!"; | ||
}); | ||
|
||
Callbacks.runThisCallback("hi", s => | ||
s ++ "concatThis!" | ||
); | ||
|
||
Callbacks.runThisCallback("hi", s => { | ||
s ++ "concatThis!"; | ||
}); | ||
|
||
Callbacks.runThisCallback("hi", s => { | ||
let s = s ++ s; | ||
s ++ "concatThis!"; | ||
}); | ||
|
||
let test = { | ||
open Callbacks; | ||
(); | ||
34; | ||
}; | ||
|
||
/* Even though these braces aren't needed we will preserve them because they | ||
* were requested */ | ||
let test = { | ||
open Callbacks; | ||
open String; | ||
34; | ||
}; | ||
|
||
/* You can have unecessary braces around inline opens even */ | ||
let test = { | ||
Callbacks.(String.(34)); | ||
}; | ||
|
||
/* Even though these braces aren't needed we will preserve them because they | ||
* were requested */ | ||
let test = { | ||
open Callbacks; | ||
String.("hello" ++ "!"); | ||
}; | ||
|
||
let test = { | ||
open Callbacks; | ||
[@attr] String.("hello" ++ "!"); | ||
}; | ||
|
||
/* Doesn't currently parse. | ||
let test = { | ||
[@attr1] | ||
open Callbacks; | ||
String.("hello" ++ "!"); | ||
}; | ||
*/ | ||
let test = { | ||
Callbacks.( | ||
{ | ||
let f = 0; | ||
f; | ||
} | ||
); | ||
}; | ||
|
||
let test = | ||
Callbacks.( | ||
{ | ||
let f = 0; | ||
f; | ||
} | ||
); |
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.
What's happening here
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.
The input file actually has braces. The old test output was stripping the braces and now this diff preserves them.
This is what the input has:
It doesn't distinguish between
[@a] { x }
and{ [@a] x }
as you can see.