Skip to content

Commit

Permalink
Synx syntax to latest master.
Browse files Browse the repository at this point in the history
commit: ac56ff7e00bcfde6e7830a05b3f65a7e9723a9d4

Fixes #5654
  • Loading branch information
cristianoc committed Sep 11, 2022
1 parent e1394d3 commit 51108cb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#### :bug: Bug Fix

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

# 10.1.0-alpha.1

Expand Down
9 changes: 6 additions & 3 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54879,13 +54879,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
[(Nolabel, lhs); (Nolabel, rhs)] )
when not
(ParsetreeViewer.isBinaryExpression lhs
|| ParsetreeViewer.isBinaryExpression rhs) ->
|| ParsetreeViewer.isBinaryExpression rhs
|| printAttributes ~customLayout expr.pexp_attributes cmtTbl
<> Doc.nil) ->
let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in
let lhsDoc = printOperand ~isLhs:true lhs op in
let rhsDoc = printOperand ~isLhs:false rhs op in
Doc.group
(Doc.concat
[
printAttributes ~customLayout expr.pexp_attributes cmtTbl;
lhsDoc;
(match (lhsHasCommentBelow, op) with
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]
Expand Down Expand Up @@ -272130,8 +272133,8 @@ module V3 = struct
| Pexp_fun (Labelled "ref", _, _, _) | Pexp_fun (Optional "ref", _, _, _)
->
raiseError ~loc:expr.pexp_loc
"Ref cannot be passed as a normal prop. Please use `forwardRef` API \
instead."
"Ref cannot be passed as a normal prop. Either give the prop a \
different name or use the `forwardRef` API instead."
| Pexp_fun (arg, default, pattern, expression)
when isOptional arg || isLabelled arg ->
let () =
Expand Down
24 changes: 17 additions & 7 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54879,13 +54879,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
[(Nolabel, lhs); (Nolabel, rhs)] )
when not
(ParsetreeViewer.isBinaryExpression lhs
|| ParsetreeViewer.isBinaryExpression rhs) ->
|| ParsetreeViewer.isBinaryExpression rhs
|| printAttributes ~customLayout expr.pexp_attributes cmtTbl
<> Doc.nil) ->
let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in
let lhsDoc = printOperand ~isLhs:true lhs op in
let rhsDoc = printOperand ~isLhs:false rhs op in
Doc.group
(Doc.concat
[
printAttributes ~customLayout expr.pexp_attributes cmtTbl;
lhsDoc;
(match (lhsHasCommentBelow, op) with
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]
Expand Down Expand Up @@ -273593,8 +273596,8 @@ module V3 = struct
| Pexp_fun (Labelled "ref", _, _, _) | Pexp_fun (Optional "ref", _, _, _)
->
raiseError ~loc:expr.pexp_loc
"Ref cannot be passed as a normal prop. Please use `forwardRef` API \
instead."
"Ref cannot be passed as a normal prop. Either give the prop a \
different name or use the `forwardRef` API instead."
| Pexp_fun (arg, default, pattern, expression)
when isOptional arg || isLabelled arg ->
let () =
Expand Down Expand Up @@ -287080,6 +287083,7 @@ and parseFieldDeclaration p =
match p.token with
| _ -> parseLident p
in
let optional = parseOptionalLabel p in
let name = Location.mkloc lident loc in
let typ =
match p.Parser.token with
Expand All @@ -287090,7 +287094,7 @@ and parseFieldDeclaration p =
Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} []
in
let loc = mkLoc startPos typ.ptyp_loc.loc_end in
Ast_helper.Type.field ~attrs ~loc ~mut name typ
(optional, Ast_helper.Type.field ~attrs ~loc ~mut name typ)

and parseFieldDeclarationRegion p =
let startPos = p.Parser.startPos in
Expand All @@ -287103,6 +287107,7 @@ and parseFieldDeclarationRegion p =
| Lident _ ->
let lident, loc = parseLident p in
let name = Location.mkloc lident loc in
(* XXX *)
let optional = parseOptionalLabel p in
let typ =
match p.Parser.token with
Expand Down Expand Up @@ -287282,7 +287287,10 @@ and parseConstrDeclArgs p =
~closing:Rbrace ~f:parseFieldDeclarationRegion p
| attrs ->
let first =
let field = parseFieldDeclaration p in
let optional, field = parseFieldDeclaration p in
let attrs =
if optional then optionalAttr :: attrs else attrs
in
Parser.expect Comma p;
{field with Parsetree.pld_attributes = attrs}
in
Expand Down Expand Up @@ -287679,13 +287687,15 @@ and parseRecordOrObjectDecl p =
| _ ->
Parser.leaveBreadcrumb p Grammar.RecordDecl;
let fields =
(* XXX *)
match attrs with
| [] ->
parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
~closing:Rbrace ~f:parseFieldDeclarationRegion p
| attr :: _ as attrs ->
let first =
let field = parseFieldDeclaration p in
let optional, field = parseFieldDeclaration p in
let attrs = if optional then optionalAttr :: attrs else attrs in
Parser.optional p Comma |> ignore;
{
field with
Expand Down Expand Up @@ -289843,9 +289853,9 @@ and printRecordDeclRowDoc (name, mut, opt, arg) =
Doc.group
(Doc.concat
[
(if opt then Doc.text "?" else Doc.nil);
(if mut then Doc.text "mutable " else Doc.nil);
printIdentLike ~allowUident:false name;
(if opt then Doc.text "?" else Doc.nil);
Doc.text ": ";
printOutTypeDoc arg;
])
Expand Down
24 changes: 17 additions & 7 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -231066,13 +231066,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
[(Nolabel, lhs); (Nolabel, rhs)] )
when not
(ParsetreeViewer.isBinaryExpression lhs
|| ParsetreeViewer.isBinaryExpression rhs) ->
|| ParsetreeViewer.isBinaryExpression rhs
|| printAttributes ~customLayout expr.pexp_attributes cmtTbl
<> Doc.nil) ->
let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in
let lhsDoc = printOperand ~isLhs:true lhs op in
let rhsDoc = printOperand ~isLhs:false rhs op in
Doc.group
(Doc.concat
[
printAttributes ~customLayout expr.pexp_attributes cmtTbl;
lhsDoc;
(match (lhsHasCommentBelow, op) with
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]
Expand Down Expand Up @@ -283972,8 +283975,8 @@ module V3 = struct
| Pexp_fun (Labelled "ref", _, _, _) | Pexp_fun (Optional "ref", _, _, _)
->
raiseError ~loc:expr.pexp_loc
"Ref cannot be passed as a normal prop. Please use `forwardRef` API \
instead."
"Ref cannot be passed as a normal prop. Either give the prop a \
different name or use the `forwardRef` API instead."
| Pexp_fun (arg, default, pattern, expression)
when isOptional arg || isLabelled arg ->
let () =
Expand Down Expand Up @@ -300604,6 +300607,7 @@ and parseFieldDeclaration p =
match p.token with
| _ -> parseLident p
in
let optional = parseOptionalLabel p in
let name = Location.mkloc lident loc in
let typ =
match p.Parser.token with
Expand All @@ -300614,7 +300618,7 @@ and parseFieldDeclaration p =
Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} []
in
let loc = mkLoc startPos typ.ptyp_loc.loc_end in
Ast_helper.Type.field ~attrs ~loc ~mut name typ
(optional, Ast_helper.Type.field ~attrs ~loc ~mut name typ)

and parseFieldDeclarationRegion p =
let startPos = p.Parser.startPos in
Expand All @@ -300627,6 +300631,7 @@ and parseFieldDeclarationRegion p =
| Lident _ ->
let lident, loc = parseLident p in
let name = Location.mkloc lident loc in
(* XXX *)
let optional = parseOptionalLabel p in
let typ =
match p.Parser.token with
Expand Down Expand Up @@ -300806,7 +300811,10 @@ and parseConstrDeclArgs p =
~closing:Rbrace ~f:parseFieldDeclarationRegion p
| attrs ->
let first =
let field = parseFieldDeclaration p in
let optional, field = parseFieldDeclaration p in
let attrs =
if optional then optionalAttr :: attrs else attrs
in
Parser.expect Comma p;
{field with Parsetree.pld_attributes = attrs}
in
Expand Down Expand Up @@ -301203,13 +301211,15 @@ and parseRecordOrObjectDecl p =
| _ ->
Parser.leaveBreadcrumb p Grammar.RecordDecl;
let fields =
(* XXX *)
match attrs with
| [] ->
parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
~closing:Rbrace ~f:parseFieldDeclarationRegion p
| attr :: _ as attrs ->
let first =
let field = parseFieldDeclaration p in
let optional, field = parseFieldDeclaration p in
let attrs = if optional then optionalAttr :: attrs else attrs in
Parser.optional p Comma |> ignore;
{
field with
Expand Down Expand Up @@ -304269,9 +304279,9 @@ and printRecordDeclRowDoc (name, mut, opt, arg) =
Doc.group
(Doc.concat
[
(if opt then Doc.text "?" else Doc.nil);
(if mut then Doc.text "mutable " else Doc.nil);
printIdentLike ~allowUident:false name;
(if opt then Doc.text "?" else Doc.nil);
Doc.text ": ";
printOutTypeDoc arg;
])
Expand Down

0 comments on commit 51108cb

Please sign in to comment.