Skip to content

Commit 51108cb

Browse files
committed
Synx syntax to latest master.
commit: ac56ff7e00bcfde6e7830a05b3f65a7e9723a9d4 Fixes #5654
1 parent e1394d3 commit 51108cb

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
#### :bug: Bug Fix
1616

17-
- Fix printing of type declarations in error message where they would be considered recursive by default
17+
- Fix printing of type declarations in error message where they would be considered recursive by default
18+
- Fix issue where the printer would omit attributes for `->` and `|>` https://github.com/rescript-lang/syntax/pull/629
19+
- Fix printing of optional fiels in records https://github.com/rescript-lang/rescript-compiler/issues/5654
1820

1921
# 10.1.0-alpha.1
2022

lib/4.06.1/unstable/js_compiler.ml

+6-3
Original file line numberDiff line numberDiff line change
@@ -54879,13 +54879,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
5487954879
[(Nolabel, lhs); (Nolabel, rhs)] )
5488054880
when not
5488154881
(ParsetreeViewer.isBinaryExpression lhs
54882-
|| ParsetreeViewer.isBinaryExpression rhs) ->
54882+
|| ParsetreeViewer.isBinaryExpression rhs
54883+
|| printAttributes ~customLayout expr.pexp_attributes cmtTbl
54884+
<> Doc.nil) ->
5488354885
let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in
5488454886
let lhsDoc = printOperand ~isLhs:true lhs op in
5488554887
let rhsDoc = printOperand ~isLhs:false rhs op in
5488654888
Doc.group
5488754889
(Doc.concat
5488854890
[
54891+
printAttributes ~customLayout expr.pexp_attributes cmtTbl;
5488954892
lhsDoc;
5489054893
(match (lhsHasCommentBelow, op) with
5489154894
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]
@@ -272130,8 +272133,8 @@ module V3 = struct
272130272133
| Pexp_fun (Labelled "ref", _, _, _) | Pexp_fun (Optional "ref", _, _, _)
272131272134
->
272132272135
raiseError ~loc:expr.pexp_loc
272133-
"Ref cannot be passed as a normal prop. Please use `forwardRef` API \
272134-
instead."
272136+
"Ref cannot be passed as a normal prop. Either give the prop a \
272137+
different name or use the `forwardRef` API instead."
272135272138
| Pexp_fun (arg, default, pattern, expression)
272136272139
when isOptional arg || isLabelled arg ->
272137272140
let () =

lib/4.06.1/unstable/js_playground_compiler.ml

+17-7
Original file line numberDiff line numberDiff line change
@@ -54879,13 +54879,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
5487954879
[(Nolabel, lhs); (Nolabel, rhs)] )
5488054880
when not
5488154881
(ParsetreeViewer.isBinaryExpression lhs
54882-
|| ParsetreeViewer.isBinaryExpression rhs) ->
54882+
|| ParsetreeViewer.isBinaryExpression rhs
54883+
|| printAttributes ~customLayout expr.pexp_attributes cmtTbl
54884+
<> Doc.nil) ->
5488354885
let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in
5488454886
let lhsDoc = printOperand ~isLhs:true lhs op in
5488554887
let rhsDoc = printOperand ~isLhs:false rhs op in
5488654888
Doc.group
5488754889
(Doc.concat
5488854890
[
54891+
printAttributes ~customLayout expr.pexp_attributes cmtTbl;
5488954892
lhsDoc;
5489054893
(match (lhsHasCommentBelow, op) with
5489154894
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]
@@ -273593,8 +273596,8 @@ module V3 = struct
273593273596
| Pexp_fun (Labelled "ref", _, _, _) | Pexp_fun (Optional "ref", _, _, _)
273594273597
->
273595273598
raiseError ~loc:expr.pexp_loc
273596-
"Ref cannot be passed as a normal prop. Please use `forwardRef` API \
273597-
instead."
273599+
"Ref cannot be passed as a normal prop. Either give the prop a \
273600+
different name or use the `forwardRef` API instead."
273598273601
| Pexp_fun (arg, default, pattern, expression)
273599273602
when isOptional arg || isLabelled arg ->
273600273603
let () =
@@ -287080,6 +287083,7 @@ and parseFieldDeclaration p =
287080287083
match p.token with
287081287084
| _ -> parseLident p
287082287085
in
287086+
let optional = parseOptionalLabel p in
287083287087
let name = Location.mkloc lident loc in
287084287088
let typ =
287085287089
match p.Parser.token with
@@ -287090,7 +287094,7 @@ and parseFieldDeclaration p =
287090287094
Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} []
287091287095
in
287092287096
let loc = mkLoc startPos typ.ptyp_loc.loc_end in
287093-
Ast_helper.Type.field ~attrs ~loc ~mut name typ
287097+
(optional, Ast_helper.Type.field ~attrs ~loc ~mut name typ)
287094287098

287095287099
and parseFieldDeclarationRegion p =
287096287100
let startPos = p.Parser.startPos in
@@ -287103,6 +287107,7 @@ and parseFieldDeclarationRegion p =
287103287107
| Lident _ ->
287104287108
let lident, loc = parseLident p in
287105287109
let name = Location.mkloc lident loc in
287110+
(* XXX *)
287106287111
let optional = parseOptionalLabel p in
287107287112
let typ =
287108287113
match p.Parser.token with
@@ -287282,7 +287287,10 @@ and parseConstrDeclArgs p =
287282287287
~closing:Rbrace ~f:parseFieldDeclarationRegion p
287283287288
| attrs ->
287284287289
let first =
287285-
let field = parseFieldDeclaration p in
287290+
let optional, field = parseFieldDeclaration p in
287291+
let attrs =
287292+
if optional then optionalAttr :: attrs else attrs
287293+
in
287286287294
Parser.expect Comma p;
287287287295
{field with Parsetree.pld_attributes = attrs}
287288287296
in
@@ -287679,13 +287687,15 @@ and parseRecordOrObjectDecl p =
287679287687
| _ ->
287680287688
Parser.leaveBreadcrumb p Grammar.RecordDecl;
287681287689
let fields =
287690+
(* XXX *)
287682287691
match attrs with
287683287692
| [] ->
287684287693
parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
287685287694
~closing:Rbrace ~f:parseFieldDeclarationRegion p
287686287695
| attr :: _ as attrs ->
287687287696
let first =
287688-
let field = parseFieldDeclaration p in
287697+
let optional, field = parseFieldDeclaration p in
287698+
let attrs = if optional then optionalAttr :: attrs else attrs in
287689287699
Parser.optional p Comma |> ignore;
287690287700
{
287691287701
field with
@@ -289843,9 +289853,9 @@ and printRecordDeclRowDoc (name, mut, opt, arg) =
289843289853
Doc.group
289844289854
(Doc.concat
289845289855
[
289846-
(if opt then Doc.text "?" else Doc.nil);
289847289856
(if mut then Doc.text "mutable " else Doc.nil);
289848289857
printIdentLike ~allowUident:false name;
289858+
(if opt then Doc.text "?" else Doc.nil);
289849289859
Doc.text ": ";
289850289860
printOutTypeDoc arg;
289851289861
])

lib/4.06.1/whole_compiler.ml

+17-7
Original file line numberDiff line numberDiff line change
@@ -231066,13 +231066,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
231066231066
[(Nolabel, lhs); (Nolabel, rhs)] )
231067231067
when not
231068231068
(ParsetreeViewer.isBinaryExpression lhs
231069-
|| ParsetreeViewer.isBinaryExpression rhs) ->
231069+
|| ParsetreeViewer.isBinaryExpression rhs
231070+
|| printAttributes ~customLayout expr.pexp_attributes cmtTbl
231071+
<> Doc.nil) ->
231070231072
let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in
231071231073
let lhsDoc = printOperand ~isLhs:true lhs op in
231072231074
let rhsDoc = printOperand ~isLhs:false rhs op in
231073231075
Doc.group
231074231076
(Doc.concat
231075231077
[
231078+
printAttributes ~customLayout expr.pexp_attributes cmtTbl;
231076231079
lhsDoc;
231077231080
(match (lhsHasCommentBelow, op) with
231078231081
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]
@@ -283972,8 +283975,8 @@ module V3 = struct
283972283975
| Pexp_fun (Labelled "ref", _, _, _) | Pexp_fun (Optional "ref", _, _, _)
283973283976
->
283974283977
raiseError ~loc:expr.pexp_loc
283975-
"Ref cannot be passed as a normal prop. Please use `forwardRef` API \
283976-
instead."
283978+
"Ref cannot be passed as a normal prop. Either give the prop a \
283979+
different name or use the `forwardRef` API instead."
283977283980
| Pexp_fun (arg, default, pattern, expression)
283978283981
when isOptional arg || isLabelled arg ->
283979283982
let () =
@@ -300604,6 +300607,7 @@ and parseFieldDeclaration p =
300604300607
match p.token with
300605300608
| _ -> parseLident p
300606300609
in
300610+
let optional = parseOptionalLabel p in
300607300611
let name = Location.mkloc lident loc in
300608300612
let typ =
300609300613
match p.Parser.token with
@@ -300614,7 +300618,7 @@ and parseFieldDeclaration p =
300614300618
Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} []
300615300619
in
300616300620
let loc = mkLoc startPos typ.ptyp_loc.loc_end in
300617-
Ast_helper.Type.field ~attrs ~loc ~mut name typ
300621+
(optional, Ast_helper.Type.field ~attrs ~loc ~mut name typ)
300618300622

300619300623
and parseFieldDeclarationRegion p =
300620300624
let startPos = p.Parser.startPos in
@@ -300627,6 +300631,7 @@ and parseFieldDeclarationRegion p =
300627300631
| Lident _ ->
300628300632
let lident, loc = parseLident p in
300629300633
let name = Location.mkloc lident loc in
300634+
(* XXX *)
300630300635
let optional = parseOptionalLabel p in
300631300636
let typ =
300632300637
match p.Parser.token with
@@ -300806,7 +300811,10 @@ and parseConstrDeclArgs p =
300806300811
~closing:Rbrace ~f:parseFieldDeclarationRegion p
300807300812
| attrs ->
300808300813
let first =
300809-
let field = parseFieldDeclaration p in
300814+
let optional, field = parseFieldDeclaration p in
300815+
let attrs =
300816+
if optional then optionalAttr :: attrs else attrs
300817+
in
300810300818
Parser.expect Comma p;
300811300819
{field with Parsetree.pld_attributes = attrs}
300812300820
in
@@ -301203,13 +301211,15 @@ and parseRecordOrObjectDecl p =
301203301211
| _ ->
301204301212
Parser.leaveBreadcrumb p Grammar.RecordDecl;
301205301213
let fields =
301214+
(* XXX *)
301206301215
match attrs with
301207301216
| [] ->
301208301217
parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
301209301218
~closing:Rbrace ~f:parseFieldDeclarationRegion p
301210301219
| attr :: _ as attrs ->
301211301220
let first =
301212-
let field = parseFieldDeclaration p in
301221+
let optional, field = parseFieldDeclaration p in
301222+
let attrs = if optional then optionalAttr :: attrs else attrs in
301213301223
Parser.optional p Comma |> ignore;
301214301224
{
301215301225
field with
@@ -304269,9 +304279,9 @@ and printRecordDeclRowDoc (name, mut, opt, arg) =
304269304279
Doc.group
304270304280
(Doc.concat
304271304281
[
304272-
(if opt then Doc.text "?" else Doc.nil);
304273304282
(if mut then Doc.text "mutable " else Doc.nil);
304274304283
printIdentLike ~allowUident:false name;
304284+
(if opt then Doc.text "?" else Doc.nil);
304275304285
Doc.text ": ";
304276304286
printOutTypeDoc arg;
304277304287
])

0 commit comments

Comments
 (0)