Skip to content

Commit ef395f6

Browse files
Remove {path as p} record pattern sugar for {path: p} (rescript-lang#416)
`{path as p}` formats to `{path: p`}, which is the right syntax. The as syntax is unnecessarily confusing sugar.
1 parent 09c3c81 commit ef395f6

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

syntax/src/res_core.ml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,15 +1380,7 @@ and parseRecordPatternField p =
13801380
~loc:label.loc
13811381
(Location.mkloc (Longident.last label.txt) label.loc)
13821382
in
1383-
match p.token with
1384-
| As -> (* {bar as baz} -> {bar: baz} *)
1385-
Parser.next p;
1386-
let (name, loc) = parseLident p in
1387-
let var = Location.mkloc name loc in
1388-
let newNameOfLabel = Ast_helper.Pat.var ~loc var in
1389-
(label, newNameOfLabel)
1390-
| _ ->
1391-
(label, pattern)
1383+
(label, pattern)
13921384

13931385
(* TODO: there are better representations than PatField|Underscore ? *)
13941386
and parseRecordPatternItem p =

syntax/tests/parsing/grammar/pattern/record.res

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ let {a} = x
22
let {a} as p = x
33
let {a,} = x // trailing comma
44
let {a, b} = x
5-
let {a as p1, b as p2} = x
5+
let {a: p1, b: p2} = x
66
let {a, b,} = x // trailing comma
77
let {ReasonReact.state} = x
88
let {ReasonReact.state: state as prevState} = x
9-
let {ReasonReact.state as theState} = x
9+
let {ReasonReact.state: theState} = x
1010
let {a: u} = x
1111
let {a: (u: int)} = x
1212
let {a: (u as p: int)} = x
1313
let {a: {x, y}} = x
14-
let {a: {x as p1, y as p2}} = x
14+
let {a: {x: p1, y: p2}} = x
1515
let {a, _ } = x
1616
let {a, _, } = x
1717
let ({a} : myRecord) = x
@@ -24,12 +24,12 @@ switch x {
2424
| {a, b,} => () // trailing comma
2525
| {ReasonReact.state} => ()
2626
| {ReasonReact.state: state as prevState} => ()
27-
| {ReasonReact.state as theState} => ()
27+
| {ReasonReact.state: theState} => ()
2828
| {a: u} => ()
2929
| {a: (u: int)} => ()
3030
| {a: (u as p: int) as p2} as p3 => ()
3131
| {a: {x, y}} => ()
32-
| {a: {x as p1, y as p2} as p3} => ()
32+
| {a: {x: p1, y: p2} as p3} => ()
3333
| {a, _ } => ()
3434
| {a, _, } => ()
3535
| ({a} : myRecord) => ()
@@ -42,12 +42,12 @@ let f = ({a, b}) => ()
4242
let f = ({a, b,}) => () // trailing comma
4343
let f = ({ReasonReact.state}) => ()
4444
let f = ({ReasonReact.state: state as prevState}) => ()
45-
let f = ({ReasonReact.state as theState}) => ()
45+
let f = ({ReasonReact.state: theState}) => ()
4646
let f = ({a: u}) => ()
4747
let f = ({a: (u: int)}) => ()
4848
let f = ({a: (u as x: int) as r}) => ()
4949
let f = ({a: {x, y}}) => ()
50-
let f = ({a: {x as r, y as r2}}) => ()
50+
let f = ({a: {x: r, y: r2}}) => ()
5151
let f = ({a, _ }) => ()
5252
let f = ({a, _,}) => ()
5353
let f = ({a}: myRecord) => ()
@@ -69,9 +69,9 @@ for (({ReasonReact.state}) in 0 to 10) { () }
6969
for {ReasonReact.state: state as prevState} in 0 to 10 { () }
7070
for ({ReasonReact.state: state as prevState} in 0 to 10) { () }
7171
for (({ReasonReact.state: state as prevState}) in 0 to 10) { () }
72-
for {ReasonReact.state as theState} in 0 to 10 { () }
73-
for ({ReasonReact.state as theState} in 0 to 10) { () }
74-
for (({ReasonReact.state as theState}) in 0 to 10) { () }
72+
for {ReasonReact.state: theState} in 0 to 10 { () }
73+
for ({ReasonReact.state: theState} in 0 to 10) { () }
74+
for (({ReasonReact.state: theState}) in 0 to 10) { () }
7575
for {a: u} in 0 to 10 { () }
7676
for (({a: u}) in 0 to 10) { () }
7777
for ({a: u} in 0 to 10) { () }
@@ -80,7 +80,7 @@ for {a: (u as sp: int) as p} in 0 to 10 { () }
8080
for (({a: (u: int)}) in 0 to 10) { () }
8181
for ({a: (u: int)} in 0 to 10) { () }
8282
for {a: {x, y}} in 0 to 10 { () }
83-
for {a: {x as p1, y as p2} as p3} in 0 to 10 { () }
83+
for {a: {x: p1, y: p2} as p3} in 0 to 10 { () }
8484
for (({a: {x, y}}) in 0 to 10) { () }
8585
for (({a: {x, y}} as p) as p2 in 0 to 10) { () }
8686
for ({a: {x, y}} in 0 to 10) { () }

syntax/tests/printer/expr/fun.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ let add = ([a, b]): array<intWithSuperLongName, stringWithSuperLongName, intWith
205205
let add = ([superLongParameterName, bsuperLongParameterName, superLongParameterName, superLongParameterName]): array<intWithSuperLongName, stringWithSuperLongName, intWithSuperLongName, intWithSuperLongName> => a + b
206206

207207
let add = ({x: superLongParameterName, y: superLongParameterName, z: superLongParameterName}) => x + y + z
208-
let add = ({x as superLongParameterName, y as superLongParameterName, z as superLongParameterName}) => x + y + z
208+
let add = ({x: superLongParameterName, y: superLongParameterName, z: superLongParameterName}) => x + y + z
209209
let add = ({x: x as superLongParameterName, y: y as superLongParameterName, z: z as superLongParameterName}) => x + y + z
210210

211211

syntax/tests/printer/pattern/record.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let {x: xCoord, y: yCoord, _} = 1
99
let {xxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzzzzzzzzz } = 1
1010
let {xxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzzzzzzzzz, _ } = 1
1111

12-
let {x as y} = z
12+
let {x: y} = z
1313
let {x: x as y} = z
1414

1515
let get_age3 = ({age: (age2: int), name: _}) => age2

0 commit comments

Comments
 (0)