Skip to content

Commit 8278bf0

Browse files
authored
sync latest syntax (#5751)
1 parent 8de6f38 commit 8278bf0

File tree

6 files changed

+58
-64
lines changed

6 files changed

+58
-64
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
1313
# 10.1.0-rc.3
1414

15+
- Fix issue where the JSX key type is not an optional string https://github.com/rescript-lang/syntax/pull/693
16+
1517
# 10.1.0-rc.2
1618

1719
#### :bug: Bug Fix

jscomp/napkin/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- Fix several printing issues with `async` including an infinite loop https://github.com/rescript-lang/syntax/pull/680
4444
- Fix issue where certain JSX expressions would be formatted differenctly in compiler 10.1.0-rc.1 https://github.com/rescript-lang/syntax/issues/675
4545
- Fix issue where printing nested pipe discards await https://github.com/rescript-lang/syntax/issues/687
46+
- Fix issue where the JSX key type is not an optional string https://github.com/rescript-lang/syntax/pull/693
4647

4748
#### :eyeglasses: Spec Compliance
4849

lib/4.06.1/unstable/js_compiler.ml

+18-21
Original file line numberDiff line numberDiff line change
@@ -273011,6 +273011,8 @@ let constantString ~loc str =
273011273011
(* {} empty record *)
273012273012
let emptyRecord ~loc = Exp.record ~loc [] None
273013273013

273014+
let unitExpr ~loc = Exp.construct ~loc (Location.mkloc (Lident "()") loc) None
273015+
273014273016
let safeTypeFromValue valueStr =
273015273017
let valueStr = getLabel valueStr in
273016273018
if valueStr = "" || (valueStr.[0] [@doesNotRaise]) <> '_' then valueStr
@@ -273360,51 +273362,46 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
273360273362
match config.mode with
273361273363
(* The new jsx transform *)
273362273364
| "automatic" ->
273363-
let jsxExpr, key =
273365+
let jsxExpr, keyAndUnit =
273364273366
match (!childrenArg, keyProp) with
273365-
| None, (_, keyExpr) :: _ ->
273367+
| None, key :: _ ->
273366273368
( Exp.ident
273367273369
{loc = Location.none; txt = Ldot (Lident "React", "jsxKeyed")},
273368-
[(nolabel, keyExpr)] )
273370+
[key; (nolabel, unitExpr ~loc:Location.none)] )
273369273371
| None, [] ->
273370273372
(Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "jsx")}, [])
273371-
| Some _, (_, keyExpr) :: _ ->
273373+
| Some _, key :: _ ->
273372273374
( Exp.ident
273373273375
{loc = Location.none; txt = Ldot (Lident "React", "jsxsKeyed")},
273374-
[(nolabel, keyExpr)] )
273376+
[key; (nolabel, unitExpr ~loc:Location.none)] )
273375273377
| Some _, [] ->
273376273378
( Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "jsxs")},
273377273379
[] )
273378273380
in
273379-
Exp.apply ~attrs jsxExpr ([(nolabel, makeID); (nolabel, props)] @ key)
273381+
Exp.apply ~attrs jsxExpr ([(nolabel, makeID); (nolabel, props)] @ keyAndUnit)
273380273382
| _ -> (
273381273383
match (!childrenArg, keyProp) with
273382-
| None, (_, keyExpr) :: _ ->
273384+
| None, key :: _ ->
273383273385
Exp.apply ~attrs
273384273386
(Exp.ident
273385273387
{
273386273388
loc = Location.none;
273387273389
txt = Ldot (Lident "React", "createElementWithKey");
273388273390
})
273389-
[(nolabel, makeID); (nolabel, props); (nolabel, keyExpr)]
273391+
[key; (nolabel, makeID); (nolabel, props)]
273390273392
| None, [] ->
273391273393
Exp.apply ~attrs
273392273394
(Exp.ident
273393273395
{loc = Location.none; txt = Ldot (Lident "React", "createElement")})
273394273396
[(nolabel, makeID); (nolabel, props)]
273395-
| Some children, (_, keyExpr) :: _ ->
273397+
| Some children, key :: _ ->
273396273398
Exp.apply ~attrs
273397273399
(Exp.ident
273398273400
{
273399273401
loc = Location.none;
273400273402
txt = Ldot (Lident "React", "createElementVariadicWithKey");
273401273403
})
273402-
[
273403-
(nolabel, makeID);
273404-
(nolabel, props);
273405-
(nolabel, children);
273406-
(nolabel, keyExpr);
273407-
]
273404+
[key; (nolabel, makeID); (nolabel, props); (nolabel, children)]
273408273405
| Some children, [] ->
273409273406
Exp.apply ~attrs
273410273407
(Exp.ident
@@ -273470,25 +273467,25 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
273470273467
let keyProp =
273471273468
args |> List.filter (fun (arg_label, _) -> "key" = getLabel arg_label)
273472273469
in
273473-
let jsxExpr, key =
273470+
let jsxExpr, keyAndUnit =
273474273471
match (!childrenArg, keyProp) with
273475-
| None, (_, keyExpr) :: _ ->
273472+
| None, key :: _ ->
273476273473
( Exp.ident
273477273474
{loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxKeyed")},
273478-
[(nolabel, keyExpr)] )
273475+
[key; (nolabel, unitExpr ~loc:Location.none)] )
273479273476
| None, [] ->
273480273477
( Exp.ident {loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsx")},
273481273478
[] )
273482-
| Some _, (_, keyExpr) :: _ ->
273479+
| Some _, key :: _ ->
273483273480
( Exp.ident
273484273481
{loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxsKeyed")},
273485-
[(nolabel, keyExpr)] )
273482+
[key; (nolabel, unitExpr ~loc:Location.none)] )
273486273483
| Some _, [] ->
273487273484
( Exp.ident {loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxs")},
273488273485
[] )
273489273486
in
273490273487
Exp.apply ~attrs jsxExpr
273491-
([(nolabel, componentNameExpr); (nolabel, props)] @ key)
273488+
([(nolabel, componentNameExpr); (nolabel, props)] @ keyAndUnit)
273492273489
| _ ->
273493273490
let children, nonChildrenProps =
273494273491
extractChildren ~loc:jsxExprLoc callArguments

lib/4.06.1/unstable/js_playground_compiler.ml

+18-21
Original file line numberDiff line numberDiff line change
@@ -274474,6 +274474,8 @@ let constantString ~loc str =
274474274474
(* {} empty record *)
274475274475
let emptyRecord ~loc = Exp.record ~loc [] None
274476274476

274477+
let unitExpr ~loc = Exp.construct ~loc (Location.mkloc (Lident "()") loc) None
274478+
274477274479
let safeTypeFromValue valueStr =
274478274480
let valueStr = getLabel valueStr in
274479274481
if valueStr = "" || (valueStr.[0] [@doesNotRaise]) <> '_' then valueStr
@@ -274823,51 +274825,46 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
274823274825
match config.mode with
274824274826
(* The new jsx transform *)
274825274827
| "automatic" ->
274826-
let jsxExpr, key =
274828+
let jsxExpr, keyAndUnit =
274827274829
match (!childrenArg, keyProp) with
274828-
| None, (_, keyExpr) :: _ ->
274830+
| None, key :: _ ->
274829274831
( Exp.ident
274830274832
{loc = Location.none; txt = Ldot (Lident "React", "jsxKeyed")},
274831-
[(nolabel, keyExpr)] )
274833+
[key; (nolabel, unitExpr ~loc:Location.none)] )
274832274834
| None, [] ->
274833274835
(Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "jsx")}, [])
274834-
| Some _, (_, keyExpr) :: _ ->
274836+
| Some _, key :: _ ->
274835274837
( Exp.ident
274836274838
{loc = Location.none; txt = Ldot (Lident "React", "jsxsKeyed")},
274837-
[(nolabel, keyExpr)] )
274839+
[key; (nolabel, unitExpr ~loc:Location.none)] )
274838274840
| Some _, [] ->
274839274841
( Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "jsxs")},
274840274842
[] )
274841274843
in
274842-
Exp.apply ~attrs jsxExpr ([(nolabel, makeID); (nolabel, props)] @ key)
274844+
Exp.apply ~attrs jsxExpr ([(nolabel, makeID); (nolabel, props)] @ keyAndUnit)
274843274845
| _ -> (
274844274846
match (!childrenArg, keyProp) with
274845-
| None, (_, keyExpr) :: _ ->
274847+
| None, key :: _ ->
274846274848
Exp.apply ~attrs
274847274849
(Exp.ident
274848274850
{
274849274851
loc = Location.none;
274850274852
txt = Ldot (Lident "React", "createElementWithKey");
274851274853
})
274852-
[(nolabel, makeID); (nolabel, props); (nolabel, keyExpr)]
274854+
[key; (nolabel, makeID); (nolabel, props)]
274853274855
| None, [] ->
274854274856
Exp.apply ~attrs
274855274857
(Exp.ident
274856274858
{loc = Location.none; txt = Ldot (Lident "React", "createElement")})
274857274859
[(nolabel, makeID); (nolabel, props)]
274858-
| Some children, (_, keyExpr) :: _ ->
274860+
| Some children, key :: _ ->
274859274861
Exp.apply ~attrs
274860274862
(Exp.ident
274861274863
{
274862274864
loc = Location.none;
274863274865
txt = Ldot (Lident "React", "createElementVariadicWithKey");
274864274866
})
274865-
[
274866-
(nolabel, makeID);
274867-
(nolabel, props);
274868-
(nolabel, children);
274869-
(nolabel, keyExpr);
274870-
]
274867+
[key; (nolabel, makeID); (nolabel, props); (nolabel, children)]
274871274868
| Some children, [] ->
274872274869
Exp.apply ~attrs
274873274870
(Exp.ident
@@ -274933,25 +274930,25 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
274933274930
let keyProp =
274934274931
args |> List.filter (fun (arg_label, _) -> "key" = getLabel arg_label)
274935274932
in
274936-
let jsxExpr, key =
274933+
let jsxExpr, keyAndUnit =
274937274934
match (!childrenArg, keyProp) with
274938-
| None, (_, keyExpr) :: _ ->
274935+
| None, key :: _ ->
274939274936
( Exp.ident
274940274937
{loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxKeyed")},
274941-
[(nolabel, keyExpr)] )
274938+
[key; (nolabel, unitExpr ~loc:Location.none)] )
274942274939
| None, [] ->
274943274940
( Exp.ident {loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsx")},
274944274941
[] )
274945-
| Some _, (_, keyExpr) :: _ ->
274942+
| Some _, key :: _ ->
274946274943
( Exp.ident
274947274944
{loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxsKeyed")},
274948-
[(nolabel, keyExpr)] )
274945+
[key; (nolabel, unitExpr ~loc:Location.none)] )
274949274946
| Some _, [] ->
274950274947
( Exp.ident {loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxs")},
274951274948
[] )
274952274949
in
274953274950
Exp.apply ~attrs jsxExpr
274954-
([(nolabel, componentNameExpr); (nolabel, props)] @ key)
274951+
([(nolabel, componentNameExpr); (nolabel, props)] @ keyAndUnit)
274955274952
| _ ->
274956274953
let children, nonChildrenProps =
274957274954
extractChildren ~loc:jsxExprLoc callArguments

lib/4.06.1/whole_compiler.ml

+18-21
Original file line numberDiff line numberDiff line change
@@ -284858,6 +284858,8 @@ let constantString ~loc str =
284858284858
(* {} empty record *)
284859284859
let emptyRecord ~loc = Exp.record ~loc [] None
284860284860

284861+
let unitExpr ~loc = Exp.construct ~loc (Location.mkloc (Lident "()") loc) None
284862+
284861284863
let safeTypeFromValue valueStr =
284862284864
let valueStr = getLabel valueStr in
284863284865
if valueStr = "" || (valueStr.[0] [@doesNotRaise]) <> '_' then valueStr
@@ -285207,51 +285209,46 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
285207285209
match config.mode with
285208285210
(* The new jsx transform *)
285209285211
| "automatic" ->
285210-
let jsxExpr, key =
285212+
let jsxExpr, keyAndUnit =
285211285213
match (!childrenArg, keyProp) with
285212-
| None, (_, keyExpr) :: _ ->
285214+
| None, key :: _ ->
285213285215
( Exp.ident
285214285216
{loc = Location.none; txt = Ldot (Lident "React", "jsxKeyed")},
285215-
[(nolabel, keyExpr)] )
285217+
[key; (nolabel, unitExpr ~loc:Location.none)] )
285216285218
| None, [] ->
285217285219
(Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "jsx")}, [])
285218-
| Some _, (_, keyExpr) :: _ ->
285220+
| Some _, key :: _ ->
285219285221
( Exp.ident
285220285222
{loc = Location.none; txt = Ldot (Lident "React", "jsxsKeyed")},
285221-
[(nolabel, keyExpr)] )
285223+
[key; (nolabel, unitExpr ~loc:Location.none)] )
285222285224
| Some _, [] ->
285223285225
( Exp.ident {loc = Location.none; txt = Ldot (Lident "React", "jsxs")},
285224285226
[] )
285225285227
in
285226-
Exp.apply ~attrs jsxExpr ([(nolabel, makeID); (nolabel, props)] @ key)
285228+
Exp.apply ~attrs jsxExpr ([(nolabel, makeID); (nolabel, props)] @ keyAndUnit)
285227285229
| _ -> (
285228285230
match (!childrenArg, keyProp) with
285229-
| None, (_, keyExpr) :: _ ->
285231+
| None, key :: _ ->
285230285232
Exp.apply ~attrs
285231285233
(Exp.ident
285232285234
{
285233285235
loc = Location.none;
285234285236
txt = Ldot (Lident "React", "createElementWithKey");
285235285237
})
285236-
[(nolabel, makeID); (nolabel, props); (nolabel, keyExpr)]
285238+
[key; (nolabel, makeID); (nolabel, props)]
285237285239
| None, [] ->
285238285240
Exp.apply ~attrs
285239285241
(Exp.ident
285240285242
{loc = Location.none; txt = Ldot (Lident "React", "createElement")})
285241285243
[(nolabel, makeID); (nolabel, props)]
285242-
| Some children, (_, keyExpr) :: _ ->
285244+
| Some children, key :: _ ->
285243285245
Exp.apply ~attrs
285244285246
(Exp.ident
285245285247
{
285246285248
loc = Location.none;
285247285249
txt = Ldot (Lident "React", "createElementVariadicWithKey");
285248285250
})
285249-
[
285250-
(nolabel, makeID);
285251-
(nolabel, props);
285252-
(nolabel, children);
285253-
(nolabel, keyExpr);
285254-
]
285251+
[key; (nolabel, makeID); (nolabel, props); (nolabel, children)]
285255285252
| Some children, [] ->
285256285253
Exp.apply ~attrs
285257285254
(Exp.ident
@@ -285317,25 +285314,25 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
285317285314
let keyProp =
285318285315
args |> List.filter (fun (arg_label, _) -> "key" = getLabel arg_label)
285319285316
in
285320-
let jsxExpr, key =
285317+
let jsxExpr, keyAndUnit =
285321285318
match (!childrenArg, keyProp) with
285322-
| None, (_, keyExpr) :: _ ->
285319+
| None, key :: _ ->
285323285320
( Exp.ident
285324285321
{loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxKeyed")},
285325-
[(nolabel, keyExpr)] )
285322+
[key; (nolabel, unitExpr ~loc:Location.none)] )
285326285323
| None, [] ->
285327285324
( Exp.ident {loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsx")},
285328285325
[] )
285329-
| Some _, (_, keyExpr) :: _ ->
285326+
| Some _, key :: _ ->
285330285327
( Exp.ident
285331285328
{loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxsKeyed")},
285332-
[(nolabel, keyExpr)] )
285329+
[key; (nolabel, unitExpr ~loc:Location.none)] )
285333285330
| Some _, [] ->
285334285331
( Exp.ident {loc = Location.none; txt = Ldot (Lident "ReactDOM", "jsxs")},
285335285332
[] )
285336285333
in
285337285334
Exp.apply ~attrs jsxExpr
285338-
([(nolabel, componentNameExpr); (nolabel, props)] @ key)
285335+
([(nolabel, componentNameExpr); (nolabel, props)] @ keyAndUnit)
285339285336
| _ ->
285340285337
let children, nonChildrenProps =
285341285338
extractChildren ~loc:jsxExprLoc callArguments

0 commit comments

Comments
 (0)