Skip to content

Commit ca89474

Browse files
mununkicristianoc
authored andcommitted
sync latest syntax
1 parent d87fb77 commit ca89474

File tree

6 files changed

+149
-73
lines changed

6 files changed

+149
-73
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
- Fix issue with async context and locally abstract types https://github.com/rescript-lang/rescript-compiler/pull/5985
2525
- Fix support for recursive components in JSX V4 https://github.com/rescript-lang/syntax/pull/733
2626
- GenType: fix issue with V3 compatibility mode (see https://github.com/rescript-lang/rescript-compiler/issues/5990) https://github.com/rescript-lang/rescript-compiler/pull/5992
27+
- Fix issue with overlapping labelled argument with default value https://github.com/rescript-lang/syntax/pull/734
28+
- Fix issue with using alias and default value together https://github.com/rescript-lang/syntax/pull/734
2729

2830
# 10.1.2
2931

jscomp/napkin/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
- Fix issue where uncurried functions were incorrectly converting the type of a prop given as a default value to curried https://github.com/rescript-lang/syntax/pull/731
6161
- Fix issue with printing async functions with locally abstract types https://github.com/rescript-lang/syntax/pull/732
6262
- Fix support for recursive components in JSX V4 https://github.com/rescript-lang/syntax/pull/733
63+
- Fix issue with overlapping labelled argument with default value https://github.com/rescript-lang/syntax/pull/734
64+
- Fix issue with using alias and default value together https://github.com/rescript-lang/syntax/pull/734
6365

6466
#### :eyeglasses: Spec Compliance
6567

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -275424,10 +275424,10 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
275424275424
:: types
275425275425
| _ -> types
275426275426

275427-
let argWithDefaultValue (name, default, _, _, _, _) =
275428-
match default with
275429-
| Some default when isOptional name -> Some (getLabel name, default)
275430-
| _ -> None
275427+
let hasDefaultValue nameArgList =
275428+
nameArgList
275429+
|> List.exists (fun (name, default, _, _, _, _) ->
275430+
Option.is_some default && isOptional name)
275431275431

275432275432
let argToConcreteType types (name, attrs, loc, type_) =
275433275433
match name with
@@ -275711,26 +275711,43 @@ let transformStructureItem ~config mapper item =
275711275711
(argToType ~newtypes ~typeConstraints)
275712275712
[] namedArgList
275713275713
in
275714-
let namedArgWithDefaultValueList =
275715-
List.filter_map argWithDefaultValue namedArgList
275714+
let vbMatch (name, default, _, alias, loc, _) =
275715+
let label = getLabel name in
275716+
match default with
275717+
| Some default ->
275718+
Vb.mk
275719+
(Pat.var (Location.mkloc alias loc))
275720+
(Exp.match_
275721+
(Exp.field
275722+
(Exp.ident {txt = Lident "props"; loc = Location.none})
275723+
(Location.mknoloc @@ Lident label))
275724+
[
275725+
Exp.case
275726+
(Pat.construct
275727+
(Location.mknoloc @@ Lident "Some")
275728+
(Some (Pat.var (Location.mknoloc label))))
275729+
(Exp.ident (Location.mknoloc @@ Lident label));
275730+
Exp.case
275731+
(Pat.construct (Location.mknoloc @@ Lident "None") None)
275732+
default;
275733+
])
275734+
| None ->
275735+
Vb.mk
275736+
(Pat.var (Location.mkloc alias loc))
275737+
(Exp.field
275738+
(Exp.ident {txt = Lident "props"; loc = Location.none})
275739+
(Location.mknoloc @@ Lident label))
275716275740
in
275717-
let vbMatch (label, default) =
275718-
Vb.mk
275719-
(Pat.var (Location.mknoloc label))
275720-
(Exp.match_
275721-
(Exp.ident {txt = Lident label; loc = Location.none})
275722-
[
275723-
Exp.case
275724-
(Pat.construct
275725-
(Location.mknoloc @@ Lident "Some")
275726-
(Some (Pat.var (Location.mknoloc label))))
275727-
(Exp.ident (Location.mknoloc @@ Lident label));
275728-
Exp.case
275729-
(Pat.construct (Location.mknoloc @@ Lident "None") None)
275730-
default;
275731-
])
275741+
let vbMatchExpr namedArgList expr =
275742+
let rec aux namedArgList =
275743+
match namedArgList with
275744+
| [] -> expr
275745+
| [namedArg] -> Exp.let_ Nonrecursive [vbMatch namedArg] expr
275746+
| namedArg :: rest ->
275747+
Exp.let_ Nonrecursive [vbMatch namedArg] (aux rest)
275748+
in
275749+
aux (List.rev namedArgList)
275732275750
in
275733-
let vbMatchList = List.map vbMatch namedArgWithDefaultValueList in
275734275751
(* type props = { ... } *)
275735275752
let propsRecordType =
275736275753
makePropsRecordType ~coreTypeOfAttr ~typVarsOfCoreType "props"
@@ -275849,20 +275866,27 @@ let transformStructureItem ~config mapper item =
275849275866
in
275850275867
(* add pattern matching for optional prop value *)
275851275868
let expression =
275852-
if List.length vbMatchList = 0 then expression
275853-
else Exp.let_ Nonrecursive vbMatchList expression
275869+
if hasDefaultValue namedArgList then
275870+
vbMatchExpr namedArgList expression
275871+
else expression
275854275872
in
275855275873
(* (ref) => expr *)
275856275874
let expression =
275857275875
List.fold_left
275858275876
(fun expr (_, pattern) -> Exp.fun_ Nolabel None pattern expr)
275859275877
expression patternsWithNolabel
275860275878
in
275879+
(* ({a, b, _}: props<'a, 'b>) *)
275861275880
let recordPattern =
275862275881
match patternsWithLabel with
275863275882
| [] -> Pat.any ()
275864275883
| _ -> Pat.record (List.rev patternsWithLabel) Open
275865275884
in
275885+
let recordPattern =
275886+
if hasDefaultValue namedArgList then
275887+
Pat.var {txt = "props"; loc = emptyLoc}
275888+
else recordPattern
275889+
in
275866275890
let expression =
275867275891
Exp.fun_ Nolabel None
275868275892
(Pat.constraint_ recordPattern

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -275424,10 +275424,10 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
275424275424
:: types
275425275425
| _ -> types
275426275426

275427-
let argWithDefaultValue (name, default, _, _, _, _) =
275428-
match default with
275429-
| Some default when isOptional name -> Some (getLabel name, default)
275430-
| _ -> None
275427+
let hasDefaultValue nameArgList =
275428+
nameArgList
275429+
|> List.exists (fun (name, default, _, _, _, _) ->
275430+
Option.is_some default && isOptional name)
275431275431

275432275432
let argToConcreteType types (name, attrs, loc, type_) =
275433275433
match name with
@@ -275711,26 +275711,43 @@ let transformStructureItem ~config mapper item =
275711275711
(argToType ~newtypes ~typeConstraints)
275712275712
[] namedArgList
275713275713
in
275714-
let namedArgWithDefaultValueList =
275715-
List.filter_map argWithDefaultValue namedArgList
275714+
let vbMatch (name, default, _, alias, loc, _) =
275715+
let label = getLabel name in
275716+
match default with
275717+
| Some default ->
275718+
Vb.mk
275719+
(Pat.var (Location.mkloc alias loc))
275720+
(Exp.match_
275721+
(Exp.field
275722+
(Exp.ident {txt = Lident "props"; loc = Location.none})
275723+
(Location.mknoloc @@ Lident label))
275724+
[
275725+
Exp.case
275726+
(Pat.construct
275727+
(Location.mknoloc @@ Lident "Some")
275728+
(Some (Pat.var (Location.mknoloc label))))
275729+
(Exp.ident (Location.mknoloc @@ Lident label));
275730+
Exp.case
275731+
(Pat.construct (Location.mknoloc @@ Lident "None") None)
275732+
default;
275733+
])
275734+
| None ->
275735+
Vb.mk
275736+
(Pat.var (Location.mkloc alias loc))
275737+
(Exp.field
275738+
(Exp.ident {txt = Lident "props"; loc = Location.none})
275739+
(Location.mknoloc @@ Lident label))
275716275740
in
275717-
let vbMatch (label, default) =
275718-
Vb.mk
275719-
(Pat.var (Location.mknoloc label))
275720-
(Exp.match_
275721-
(Exp.ident {txt = Lident label; loc = Location.none})
275722-
[
275723-
Exp.case
275724-
(Pat.construct
275725-
(Location.mknoloc @@ Lident "Some")
275726-
(Some (Pat.var (Location.mknoloc label))))
275727-
(Exp.ident (Location.mknoloc @@ Lident label));
275728-
Exp.case
275729-
(Pat.construct (Location.mknoloc @@ Lident "None") None)
275730-
default;
275731-
])
275741+
let vbMatchExpr namedArgList expr =
275742+
let rec aux namedArgList =
275743+
match namedArgList with
275744+
| [] -> expr
275745+
| [namedArg] -> Exp.let_ Nonrecursive [vbMatch namedArg] expr
275746+
| namedArg :: rest ->
275747+
Exp.let_ Nonrecursive [vbMatch namedArg] (aux rest)
275748+
in
275749+
aux (List.rev namedArgList)
275732275750
in
275733-
let vbMatchList = List.map vbMatch namedArgWithDefaultValueList in
275734275751
(* type props = { ... } *)
275735275752
let propsRecordType =
275736275753
makePropsRecordType ~coreTypeOfAttr ~typVarsOfCoreType "props"
@@ -275849,20 +275866,27 @@ let transformStructureItem ~config mapper item =
275849275866
in
275850275867
(* add pattern matching for optional prop value *)
275851275868
let expression =
275852-
if List.length vbMatchList = 0 then expression
275853-
else Exp.let_ Nonrecursive vbMatchList expression
275869+
if hasDefaultValue namedArgList then
275870+
vbMatchExpr namedArgList expression
275871+
else expression
275854275872
in
275855275873
(* (ref) => expr *)
275856275874
let expression =
275857275875
List.fold_left
275858275876
(fun expr (_, pattern) -> Exp.fun_ Nolabel None pattern expr)
275859275877
expression patternsWithNolabel
275860275878
in
275879+
(* ({a, b, _}: props<'a, 'b>) *)
275861275880
let recordPattern =
275862275881
match patternsWithLabel with
275863275882
| [] -> Pat.any ()
275864275883
| _ -> Pat.record (List.rev patternsWithLabel) Open
275865275884
in
275885+
let recordPattern =
275886+
if hasDefaultValue namedArgList then
275887+
Pat.var {txt = "props"; loc = emptyLoc}
275888+
else recordPattern
275889+
in
275866275890
let expression =
275867275891
Exp.fun_ Nolabel None
275868275892
(Pat.constraint_ recordPattern

lib/4.06.1/whole_compiler.ml

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -285811,10 +285811,10 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
285811285811
:: types
285812285812
| _ -> types
285813285813

285814-
let argWithDefaultValue (name, default, _, _, _, _) =
285815-
match default with
285816-
| Some default when isOptional name -> Some (getLabel name, default)
285817-
| _ -> None
285814+
let hasDefaultValue nameArgList =
285815+
nameArgList
285816+
|> List.exists (fun (name, default, _, _, _, _) ->
285817+
Option.is_some default && isOptional name)
285818285818

285819285819
let argToConcreteType types (name, attrs, loc, type_) =
285820285820
match name with
@@ -286098,26 +286098,43 @@ let transformStructureItem ~config mapper item =
286098286098
(argToType ~newtypes ~typeConstraints)
286099286099
[] namedArgList
286100286100
in
286101-
let namedArgWithDefaultValueList =
286102-
List.filter_map argWithDefaultValue namedArgList
286101+
let vbMatch (name, default, _, alias, loc, _) =
286102+
let label = getLabel name in
286103+
match default with
286104+
| Some default ->
286105+
Vb.mk
286106+
(Pat.var (Location.mkloc alias loc))
286107+
(Exp.match_
286108+
(Exp.field
286109+
(Exp.ident {txt = Lident "props"; loc = Location.none})
286110+
(Location.mknoloc @@ Lident label))
286111+
[
286112+
Exp.case
286113+
(Pat.construct
286114+
(Location.mknoloc @@ Lident "Some")
286115+
(Some (Pat.var (Location.mknoloc label))))
286116+
(Exp.ident (Location.mknoloc @@ Lident label));
286117+
Exp.case
286118+
(Pat.construct (Location.mknoloc @@ Lident "None") None)
286119+
default;
286120+
])
286121+
| None ->
286122+
Vb.mk
286123+
(Pat.var (Location.mkloc alias loc))
286124+
(Exp.field
286125+
(Exp.ident {txt = Lident "props"; loc = Location.none})
286126+
(Location.mknoloc @@ Lident label))
286103286127
in
286104-
let vbMatch (label, default) =
286105-
Vb.mk
286106-
(Pat.var (Location.mknoloc label))
286107-
(Exp.match_
286108-
(Exp.ident {txt = Lident label; loc = Location.none})
286109-
[
286110-
Exp.case
286111-
(Pat.construct
286112-
(Location.mknoloc @@ Lident "Some")
286113-
(Some (Pat.var (Location.mknoloc label))))
286114-
(Exp.ident (Location.mknoloc @@ Lident label));
286115-
Exp.case
286116-
(Pat.construct (Location.mknoloc @@ Lident "None") None)
286117-
default;
286118-
])
286128+
let vbMatchExpr namedArgList expr =
286129+
let rec aux namedArgList =
286130+
match namedArgList with
286131+
| [] -> expr
286132+
| [namedArg] -> Exp.let_ Nonrecursive [vbMatch namedArg] expr
286133+
| namedArg :: rest ->
286134+
Exp.let_ Nonrecursive [vbMatch namedArg] (aux rest)
286135+
in
286136+
aux (List.rev namedArgList)
286119286137
in
286120-
let vbMatchList = List.map vbMatch namedArgWithDefaultValueList in
286121286138
(* type props = { ... } *)
286122286139
let propsRecordType =
286123286140
makePropsRecordType ~coreTypeOfAttr ~typVarsOfCoreType "props"
@@ -286236,20 +286253,27 @@ let transformStructureItem ~config mapper item =
286236286253
in
286237286254
(* add pattern matching for optional prop value *)
286238286255
let expression =
286239-
if List.length vbMatchList = 0 then expression
286240-
else Exp.let_ Nonrecursive vbMatchList expression
286256+
if hasDefaultValue namedArgList then
286257+
vbMatchExpr namedArgList expression
286258+
else expression
286241286259
in
286242286260
(* (ref) => expr *)
286243286261
let expression =
286244286262
List.fold_left
286245286263
(fun expr (_, pattern) -> Exp.fun_ Nolabel None pattern expr)
286246286264
expression patternsWithNolabel
286247286265
in
286266+
(* ({a, b, _}: props<'a, 'b>) *)
286248286267
let recordPattern =
286249286268
match patternsWithLabel with
286250286269
| [] -> Pat.any ()
286251286270
| _ -> Pat.record (List.rev patternsWithLabel) Open
286252286271
in
286272+
let recordPattern =
286273+
if hasDefaultValue namedArgList then
286274+
Pat.var {txt = "props"; loc = emptyLoc}
286275+
else recordPattern
286276+
in
286253286277
let expression =
286254286278
Exp.fun_ Nolabel None
286255286279
(Pat.constraint_ recordPattern

0 commit comments

Comments
 (0)