Skip to content

Commit 58a5f40

Browse files
committed
Sync syntax: printing JSX spread.
1 parent b584d3f commit 58a5f40

File tree

5 files changed

+120
-6
lines changed

5 files changed

+120
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#### :bug: Bug Fix
2323

24+
- Fix issue in formatting JSX spread props https://github.com/rescript-lang/syntax/pull/644
2425
- Fix location issue in error messages with JSX V4 where the body of the component is an application https://github.com/rescript-lang/syntax/pull/633
2526
- Fix printing of type declarations in error message where they would be considered recursive by default
2627
- Fix issue where the printer would omit attributes for `->` and `|>` https://github.com/rescript-lang/syntax/pull/629

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55391,6 +55391,9 @@ and printJsxProp ~customLayout arg cmtTbl =
5539155391
| Nolabel -> Doc.nil
5539255392
| Labelled _lbl -> printIdentLike ident
5539355393
| Optional _lbl -> Doc.concat [Doc.question; printIdentLike ident])
55394+
| Asttypes.Labelled "_spreadProps", expr ->
55395+
let doc = printExpressionWithComments ~customLayout expr cmtTbl in
55396+
Doc.concat [Doc.lbrace; Doc.dotdotdot; Doc.softLine; doc; Doc.rbrace]
5539455397
| lbl, expr ->
5539555398
let argLoc, expr =
5539655399
match expr.pexp_attributes with
@@ -272990,7 +272993,7 @@ let recordFromProps ~loc ~removeKey callArguments =
272990272993
let props, propsToSpread =
272991272994
removeLastPositionUnitAux callArguments []
272992272995
|> List.rev
272993-
|> List.partition (fun (label, _) -> label <> labelled "spreadProps")
272996+
|> List.partition (fun (label, _) -> label <> labelled "_spreadProps")
272994272997
in
272995272998
let props =
272996272999
if removeKey then

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55391,6 +55391,9 @@ and printJsxProp ~customLayout arg cmtTbl =
5539155391
| Nolabel -> Doc.nil
5539255392
| Labelled _lbl -> printIdentLike ident
5539355393
| Optional _lbl -> Doc.concat [Doc.question; printIdentLike ident])
55394+
| Asttypes.Labelled "_spreadProps", expr ->
55395+
let doc = printExpressionWithComments ~customLayout expr cmtTbl in
55396+
Doc.concat [Doc.lbrace; Doc.dotdotdot; Doc.softLine; doc; Doc.rbrace]
5539455397
| lbl, expr ->
5539555398
let argLoc, expr =
5539655399
match expr.pexp_attributes with
@@ -274453,7 +274456,7 @@ let recordFromProps ~loc ~removeKey callArguments =
274453274456
let props, propsToSpread =
274454274457
removeLastPositionUnitAux callArguments []
274455274458
|> List.rev
274456-
|> List.partition (fun (label, _) -> label <> labelled "spreadProps")
274459+
|> List.partition (fun (label, _) -> label <> labelled "_spreadProps")
274457274460
in
274458274461
let props =
274459274462
if removeKey then
@@ -285433,7 +285436,7 @@ and parseJsxProp p =
285433285436
{e with pexp_attributes = propLocAttr :: e.pexp_attributes}
285434285437
in
285435285438
(* using label "spreadProps" to distinguish from others *)
285436-
let label = Asttypes.Labelled "spreadProps" in
285439+
let label = Asttypes.Labelled "_spreadProps" in
285437285440
match p.Parser.token with
285438285441
| Rbrace ->
285439285442
Parser.next p;
@@ -289146,6 +289149,20 @@ type 'diagnostics parsingEngine = {
289146289149
stringOfDiagnostics: source:string -> filename:string -> 'diagnostics -> unit;
289147289150
}
289148289151

289152+
val parseImplementationFromSource :
289153+
forPrinter:bool ->
289154+
displayFilename:string ->
289155+
source:string ->
289156+
(Parsetree.structure, Res_diagnostics.t list) parseResult
289157+
[@@live]
289158+
289159+
val parseInterfaceFromSource :
289160+
forPrinter:bool ->
289161+
displayFilename:string ->
289162+
source:string ->
289163+
(Parsetree.signature, Res_diagnostics.t list) parseResult
289164+
[@@live]
289165+
289149289166
type printEngine = {
289150289167
printImplementation:
289151289168
width:int ->
@@ -289218,6 +289235,10 @@ let setup ~filename ~forPrinter () =
289218289235
let mode = if forPrinter then Res_parser.Default else ParseForTypeChecker in
289219289236
Res_parser.make ~mode src filename
289220289237

289238+
let setupFromSource ~displayFilename ~source ~forPrinter () =
289239+
let mode = if forPrinter then Res_parser.Default else ParseForTypeChecker in
289240+
Res_parser.make ~mode source displayFilename
289241+
289221289242
let parsingEngine =
289222289243
{
289223289244
parseImplementation =
@@ -289259,6 +289280,40 @@ let parsingEngine =
289259289280
Res_diagnostics.printReport diagnostics source);
289260289281
}
289261289282

289283+
let parseImplementationFromSource ~forPrinter ~displayFilename ~source =
289284+
let engine = setupFromSource ~displayFilename ~source ~forPrinter () in
289285+
let structure = Res_core.parseImplementation engine in
289286+
let invalid, diagnostics =
289287+
match engine.diagnostics with
289288+
| [] as diagnostics -> (false, diagnostics)
289289+
| _ as diagnostics -> (true, diagnostics)
289290+
in
289291+
{
289292+
filename = engine.scanner.filename;
289293+
source = engine.scanner.src;
289294+
parsetree = structure;
289295+
diagnostics;
289296+
invalid;
289297+
comments = List.rev engine.comments;
289298+
}
289299+
289300+
let parseInterfaceFromSource ~forPrinter ~displayFilename ~source =
289301+
let engine = setupFromSource ~displayFilename ~source ~forPrinter () in
289302+
let signature = Res_core.parseSpecification engine in
289303+
let invalid, diagnostics =
289304+
match engine.diagnostics with
289305+
| [] as diagnostics -> (false, diagnostics)
289306+
| _ as diagnostics -> (true, diagnostics)
289307+
in
289308+
{
289309+
filename = engine.scanner.filename;
289310+
source = engine.scanner.src;
289311+
parsetree = signature;
289312+
diagnostics;
289313+
invalid;
289314+
comments = List.rev engine.comments;
289315+
}
289316+
289262289317
let printEngine =
289263289318
{
289264289319
printImplementation =

lib/4.06.1/whole_compiler.ml

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231578,6 +231578,9 @@ and printJsxProp ~customLayout arg cmtTbl =
231578231578
| Nolabel -> Doc.nil
231579231579
| Labelled _lbl -> printIdentLike ident
231580231580
| Optional _lbl -> Doc.concat [Doc.question; printIdentLike ident])
231581+
| Asttypes.Labelled "_spreadProps", expr ->
231582+
let doc = printExpressionWithComments ~customLayout expr cmtTbl in
231583+
Doc.concat [Doc.lbrace; Doc.dotdotdot; Doc.softLine; doc; Doc.rbrace]
231581231584
| lbl, expr ->
231582231585
let argLoc, expr =
231583231586
match expr.pexp_attributes with
@@ -284832,7 +284835,7 @@ let recordFromProps ~loc ~removeKey callArguments =
284832284835
let props, propsToSpread =
284833284836
removeLastPositionUnitAux callArguments []
284834284837
|> List.rev
284835-
|> List.partition (fun (label, _) -> label <> labelled "spreadProps")
284838+
|> List.partition (fun (label, _) -> label <> labelled "_spreadProps")
284836284839
in
284837284840
let props =
284838284841
if removeKey then
@@ -298957,7 +298960,7 @@ and parseJsxProp p =
298957298960
{e with pexp_attributes = propLocAttr :: e.pexp_attributes}
298958298961
in
298959298962
(* using label "spreadProps" to distinguish from others *)
298960-
let label = Asttypes.Labelled "spreadProps" in
298963+
let label = Asttypes.Labelled "_spreadProps" in
298961298964
match p.Parser.token with
298962298965
| Rbrace ->
298963298966
Parser.next p;
@@ -302670,6 +302673,20 @@ type 'diagnostics parsingEngine = {
302670302673
stringOfDiagnostics: source:string -> filename:string -> 'diagnostics -> unit;
302671302674
}
302672302675

302676+
val parseImplementationFromSource :
302677+
forPrinter:bool ->
302678+
displayFilename:string ->
302679+
source:string ->
302680+
(Parsetree.structure, Res_diagnostics.t list) parseResult
302681+
[@@live]
302682+
302683+
val parseInterfaceFromSource :
302684+
forPrinter:bool ->
302685+
displayFilename:string ->
302686+
source:string ->
302687+
(Parsetree.signature, Res_diagnostics.t list) parseResult
302688+
[@@live]
302689+
302673302690
type printEngine = {
302674302691
printImplementation:
302675302692
width:int ->
@@ -302742,6 +302759,10 @@ let setup ~filename ~forPrinter () =
302742302759
let mode = if forPrinter then Res_parser.Default else ParseForTypeChecker in
302743302760
Res_parser.make ~mode src filename
302744302761

302762+
let setupFromSource ~displayFilename ~source ~forPrinter () =
302763+
let mode = if forPrinter then Res_parser.Default else ParseForTypeChecker in
302764+
Res_parser.make ~mode source displayFilename
302765+
302745302766
let parsingEngine =
302746302767
{
302747302768
parseImplementation =
@@ -302783,6 +302804,40 @@ let parsingEngine =
302783302804
Res_diagnostics.printReport diagnostics source);
302784302805
}
302785302806

302807+
let parseImplementationFromSource ~forPrinter ~displayFilename ~source =
302808+
let engine = setupFromSource ~displayFilename ~source ~forPrinter () in
302809+
let structure = Res_core.parseImplementation engine in
302810+
let invalid, diagnostics =
302811+
match engine.diagnostics with
302812+
| [] as diagnostics -> (false, diagnostics)
302813+
| _ as diagnostics -> (true, diagnostics)
302814+
in
302815+
{
302816+
filename = engine.scanner.filename;
302817+
source = engine.scanner.src;
302818+
parsetree = structure;
302819+
diagnostics;
302820+
invalid;
302821+
comments = List.rev engine.comments;
302822+
}
302823+
302824+
let parseInterfaceFromSource ~forPrinter ~displayFilename ~source =
302825+
let engine = setupFromSource ~displayFilename ~source ~forPrinter () in
302826+
let signature = Res_core.parseSpecification engine in
302827+
let invalid, diagnostics =
302828+
match engine.diagnostics with
302829+
| [] as diagnostics -> (false, diagnostics)
302830+
| _ as diagnostics -> (true, diagnostics)
302831+
in
302832+
{
302833+
filename = engine.scanner.filename;
302834+
source = engine.scanner.src;
302835+
parsetree = signature;
302836+
diagnostics;
302837+
invalid;
302838+
comments = List.rev engine.comments;
302839+
}
302840+
302786302841
let printEngine =
302787302842
{
302788302843
printImplementation =

0 commit comments

Comments
 (0)