Skip to content

Sync syntax to latest master. #5656

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

Merged
merged 2 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 fields 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