Skip to content

Commit 1b2d033

Browse files
committed
Backwards-compatible check for braces attribute.
1 parent d7cab95 commit 1b2d033

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

analysis/tests/src/expected/Xform.res.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ Hit: Add braces to function
4141
{"start": {"line": 26, "character": 0}, "end": {"line": 32, "character": 3}}
4242
newText:
4343
<--here
44-
let foo = x =>
44+
let foo = x => {
4545
// ^xfm
46-
@ns.braces
4746
switch x {
4847
| None => 33
4948
| Some(q) => q.T.a + 1
5049
// ^xfm
5150
}
51+
}
5252

5353
Xform src/Xform.res 34:21
5454
Hit: Add type annotation
@@ -71,15 +71,19 @@ Hit: Add braces to function
7171
{"start": {"line": 48, "character": 0}, "end": {"line": 48, "character": 25}}
7272
newText:
7373
<--here
74-
let noBraces = () => @ns.braces name
74+
let noBraces = () => {
75+
name
76+
}
7577

7678
Xform src/Xform.res 52:34
7779
Hit: Add braces to function
7880
{"start": {"line": 51, "character": 0}, "end": {"line": 54, "character": 1}}
7981
newText:
8082
<--here
8183
let nested = () => {
82-
let _noBraces = (_x, _y, _z) => @ns.braces "someNewFunc"
84+
let _noBraces = (_x, _y, _z) => {
85+
"someNewFunc"
86+
}
8387
// ^xfm
8488
}
8589

@@ -88,10 +92,10 @@ Hit: Add braces to function
8892
{"start": {"line": 58, "character": 4}, "end": {"line": 62, "character": 7}}
8993
newText:
9094
<--here
91-
let foo = (_x, y, _z) =>
92-
@ns.braces
95+
let foo = (_x, y, _z) => {
9396
switch y {
9497
| #some => 3
9598
| #stuff => 4
9699
}
100+
}
97101

analysis/vendor/res_outcome_printer/res_comments_table.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ let getLoc node =
360360
| _ -> expr.pexp_loc)
361361
| Expression e -> (
362362
match e.pexp_attributes with
363-
| ({txt = "res.braces"; loc}, _) :: _ -> loc
363+
| ({txt = "res.braces"| "ns.braces"; loc}, _) :: _ -> loc
364364
| _ -> e.pexp_loc)
365365
| ExprRecordRow (li, e) -> {li.loc with loc_end = e.pexp_loc.loc_end}
366366
| ExtensionConstructor ec -> ec.pext_loc

analysis/vendor/res_outcome_printer/res_parsetree_viewer.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ let funExpr expr =
193193

194194
let processBracesAttr expr =
195195
match expr.pexp_attributes with
196-
| (({txt = "res.braces"}, _) as attr) :: attrs ->
196+
| (({txt = "res.braces" | "ns.braces"}, _) as attr) :: attrs ->
197197
(Some attr, {expr with pexp_attributes = attrs})
198198
| _ -> (None, expr)
199199

@@ -203,7 +203,7 @@ let filterParsingAttrs attrs =
203203
match attr with
204204
| ( {
205205
Location.txt =
206-
( "bs" | "res.uapp" | "res.arity" | "res.braces" | "res.iflet"
206+
( "bs" | "res.uapp" | "res.arity" | "res.braces"| "ns.braces" | "res.iflet"
207207
| "res.namedArgLoc" | "res.optional" | "res.ternary" | "res.async"
208208
| "res.await" | "res.template" );
209209
},
@@ -357,7 +357,7 @@ let hasAttributes attrs =
357357
match attr with
358358
| ( {
359359
Location.txt =
360-
( "bs" | "res.uapp" | "res.arity" | "res.braces" | "res.iflet"
360+
( "bs" | "res.uapp" | "res.arity" | "res.braces"| "ns.braces" | "res.iflet"
361361
| "res.ternary" | "res.async" | "res.await" | "res.template" );
362362
},
363363
_ ) ->
@@ -539,7 +539,7 @@ let isPrintableAttribute attr =
539539
match attr with
540540
| ( {
541541
Location.txt =
542-
( "bs" | "res.uapp" | "res.arity" | "res.iflet" | "res.braces" | "JSX"
542+
( "bs" | "res.uapp" | "res.arity" | "res.iflet" | "res.braces"| "ns.braces" | "JSX"
543543
| "res.async" | "res.await" | "res.template" | "res.ternary" );
544544
},
545545
_ ) ->

analysis/vendor/res_outcome_printer/res_printer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3270,7 +3270,7 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
32703270
pexp_attributes =
32713271
List.filter
32723272
(function
3273-
| {Location.txt = "res.braces"}, _ -> false
3273+
| {Location.txt = "res.braces"| "ns.braces"}, _ -> false
32743274
| _ -> true)
32753275
e.pexp_attributes;
32763276
}

0 commit comments

Comments
 (0)