Skip to content

Commit f300998

Browse files
committed
Sync latest syntax.
1 parent 6a951ee commit f300998

File tree

6 files changed

+42
-115
lines changed

6 files changed

+42
-115
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- Fix formatting of props spread for multiline JSX expression https://github.com/rescript-lang/syntax/pull/736
4040
- Support `@gentype.import` as an alias to `@genType.import` in the compiler https://github.com/rescript-lang/rescript-compiler/pull/6021
4141
- In GenType, check annotations also in module types to decide whether to produce the `.gen.tsx` file https://github.com/rescript-lang/rescript-compiler/pull/5903
42+
- Fix issue with JSX V4 and newtype https://github.com/rescript-lang/syntax/pull/737
4243

4344
#### :rocket: New Feature
4445

jscomp/napkin/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
- Fix issue with using alias and default value together https://github.com/rescript-lang/syntax/pull/734
6565
- Fix formatting of `switch` expressions that contain braced `cases` inside https://github.com/rescript-lang/syntax/pull/735
6666
- Fix formatting of props spread for multiline JSX expression https://github.com/rescript-lang/syntax/pull/736
67+
- Fix issue with JSX V4 and newtype https://github.com/rescript-lang/syntax/pull/737
6768

6869
#### :eyeglasses: Spec Compliance
6970

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -274995,7 +274995,7 @@ let makePropsTypeParams ?(stripExplicitOption = false)
274995274995
For example, if JSX ppx is used for React Native, type would be different.
274996274996
*)
274997274997
match interiorType with
274998-
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType loc)
274998+
| {ptyp_desc = Ptyp_any} -> Some (refType loc)
274999274999
| _ ->
275000275000
(* Strip explicit Js.Nullable.t in case of forwardRef *)
275001275001
if stripExplicitJsNullableOfRef then stripJsNullable interiorType
@@ -275405,46 +275405,18 @@ let rec recursivelyTransformNamedArgsForMake mapper expr args newtypes coreType
275405275405
(Some coreType)
275406275406
| _ -> (args, newtypes, coreType)
275407275407

275408-
let newtypeToVar newtype type_ =
275409-
let var_desc = Ptyp_var ("type-" ^ newtype) in
275410-
let typ (mapper : Ast_mapper.mapper) typ =
275411-
match typ.ptyp_desc with
275412-
| Ptyp_constr ({txt = Lident name}, _) when name = newtype ->
275413-
{typ with ptyp_desc = var_desc}
275414-
| _ -> Ast_mapper.default_mapper.typ mapper typ
275415-
in
275416-
let mapper = {Ast_mapper.default_mapper with typ} in
275417-
mapper.typ mapper type_
275418-
275419-
let argToType ~newtypes ~(typeConstraints : core_type option) types
275408+
let argToType types
275420275409
((name, default, {ppat_attributes = attrs}, _alias, loc, type_) :
275421275410
arg_label * expression option * pattern * label * 'loc * core_type option)
275422275411
=
275423-
let rec getType name coreType =
275424-
match coreType with
275425-
| {ptyp_desc = Ptyp_arrow (arg, c1, c2)} ->
275426-
if name = arg then Some c1 else getType name c2
275427-
| _ -> None
275428-
in
275429-
let typeConst = Option.bind typeConstraints (getType name) in
275430-
let type_ =
275431-
List.fold_left
275432-
(fun type_ newtype ->
275433-
match (type_, typeConst) with
275434-
| _, Some typ | Some typ, None -> Some (newtypeToVar newtype.txt typ)
275435-
| _ -> None)
275436-
type_ newtypes
275437-
in
275438275412
match (type_, name, default) with
275439275413
| Some type_, name, _ when isOptional name ->
275440275414
(true, getLabel name, attrs, loc, type_) :: types
275441275415
| Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types
275442275416
| None, name, _ when isOptional name ->
275443-
(true, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
275444-
:: types
275417+
(true, getLabel name, attrs, loc, Typ.any ~loc ()) :: types
275445275418
| None, name, _ when isLabelled name ->
275446-
(false, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
275447-
:: types
275419+
(false, getLabel name, attrs, loc, Typ.any ~loc ()) :: types
275448275420
| _ -> types
275449275421

275450275422
let hasDefaultValue nameArgList =
@@ -275724,16 +275696,12 @@ let transformStructureItem ~config mapper item =
275724275696
modifiedBinding binding
275725275697
in
275726275698
(* do stuff here! *)
275727-
let namedArgList, newtypes, typeConstraints =
275699+
let namedArgList, newtypes, _typeConstraints =
275728275700
recursivelyTransformNamedArgsForMake mapper
275729275701
(modifiedBindingOld binding)
275730275702
[] [] None
275731275703
in
275732-
let namedTypeList =
275733-
List.fold_left
275734-
(argToType ~newtypes ~typeConstraints)
275735-
[] namedArgList
275736-
in
275704+
let namedTypeList = List.fold_left argToType [] namedArgList in
275737275705
let vbMatch (name, default, _, alias, loc, _) =
275738275706
let label = getLabel name in
275739275707
match default with
@@ -275926,6 +275894,13 @@ let transformStructureItem ~config mapper item =
275926275894
| _ -> [Typ.any ()]))))
275927275895
expression
275928275896
in
275897+
let expression =
275898+
(* Add new tupes (type a,b,c) to make's definition *)
275899+
newtypes
275900+
|> List.fold_left
275901+
(fun e newtype -> Exp.newtype newtype e)
275902+
expression
275903+
in
275929275904
(* let make = ({id, name, ...}: props<'id, 'name, ...>) => { ... } *)
275930275905
let bindings, newBinding =
275931275906
match recFlag with

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -274995,7 +274995,7 @@ let makePropsTypeParams ?(stripExplicitOption = false)
274995274995
For example, if JSX ppx is used for React Native, type would be different.
274996274996
*)
274997274997
match interiorType with
274998-
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType loc)
274998+
| {ptyp_desc = Ptyp_any} -> Some (refType loc)
274999274999
| _ ->
275000275000
(* Strip explicit Js.Nullable.t in case of forwardRef *)
275001275001
if stripExplicitJsNullableOfRef then stripJsNullable interiorType
@@ -275405,46 +275405,18 @@ let rec recursivelyTransformNamedArgsForMake mapper expr args newtypes coreType
275405275405
(Some coreType)
275406275406
| _ -> (args, newtypes, coreType)
275407275407

275408-
let newtypeToVar newtype type_ =
275409-
let var_desc = Ptyp_var ("type-" ^ newtype) in
275410-
let typ (mapper : Ast_mapper.mapper) typ =
275411-
match typ.ptyp_desc with
275412-
| Ptyp_constr ({txt = Lident name}, _) when name = newtype ->
275413-
{typ with ptyp_desc = var_desc}
275414-
| _ -> Ast_mapper.default_mapper.typ mapper typ
275415-
in
275416-
let mapper = {Ast_mapper.default_mapper with typ} in
275417-
mapper.typ mapper type_
275418-
275419-
let argToType ~newtypes ~(typeConstraints : core_type option) types
275408+
let argToType types
275420275409
((name, default, {ppat_attributes = attrs}, _alias, loc, type_) :
275421275410
arg_label * expression option * pattern * label * 'loc * core_type option)
275422275411
=
275423-
let rec getType name coreType =
275424-
match coreType with
275425-
| {ptyp_desc = Ptyp_arrow (arg, c1, c2)} ->
275426-
if name = arg then Some c1 else getType name c2
275427-
| _ -> None
275428-
in
275429-
let typeConst = Option.bind typeConstraints (getType name) in
275430-
let type_ =
275431-
List.fold_left
275432-
(fun type_ newtype ->
275433-
match (type_, typeConst) with
275434-
| _, Some typ | Some typ, None -> Some (newtypeToVar newtype.txt typ)
275435-
| _ -> None)
275436-
type_ newtypes
275437-
in
275438275412
match (type_, name, default) with
275439275413
| Some type_, name, _ when isOptional name ->
275440275414
(true, getLabel name, attrs, loc, type_) :: types
275441275415
| Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types
275442275416
| None, name, _ when isOptional name ->
275443-
(true, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
275444-
:: types
275417+
(true, getLabel name, attrs, loc, Typ.any ~loc ()) :: types
275445275418
| None, name, _ when isLabelled name ->
275446-
(false, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
275447-
:: types
275419+
(false, getLabel name, attrs, loc, Typ.any ~loc ()) :: types
275448275420
| _ -> types
275449275421

275450275422
let hasDefaultValue nameArgList =
@@ -275724,16 +275696,12 @@ let transformStructureItem ~config mapper item =
275724275696
modifiedBinding binding
275725275697
in
275726275698
(* do stuff here! *)
275727-
let namedArgList, newtypes, typeConstraints =
275699+
let namedArgList, newtypes, _typeConstraints =
275728275700
recursivelyTransformNamedArgsForMake mapper
275729275701
(modifiedBindingOld binding)
275730275702
[] [] None
275731275703
in
275732-
let namedTypeList =
275733-
List.fold_left
275734-
(argToType ~newtypes ~typeConstraints)
275735-
[] namedArgList
275736-
in
275704+
let namedTypeList = List.fold_left argToType [] namedArgList in
275737275705
let vbMatch (name, default, _, alias, loc, _) =
275738275706
let label = getLabel name in
275739275707
match default with
@@ -275926,6 +275894,13 @@ let transformStructureItem ~config mapper item =
275926275894
| _ -> [Typ.any ()]))))
275927275895
expression
275928275896
in
275897+
let expression =
275898+
(* Add new tupes (type a,b,c) to make's definition *)
275899+
newtypes
275900+
|> List.fold_left
275901+
(fun e newtype -> Exp.newtype newtype e)
275902+
expression
275903+
in
275929275904
(* let make = ({id, name, ...}: props<'id, 'name, ...>) => { ... } *)
275930275905
let bindings, newBinding =
275931275906
match recFlag with

lib/4.06.1/whole_compiler.ml

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -285392,7 +285392,7 @@ let makePropsTypeParams ?(stripExplicitOption = false)
285392285392
For example, if JSX ppx is used for React Native, type would be different.
285393285393
*)
285394285394
match interiorType with
285395-
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType loc)
285395+
| {ptyp_desc = Ptyp_any} -> Some (refType loc)
285396285396
| _ ->
285397285397
(* Strip explicit Js.Nullable.t in case of forwardRef *)
285398285398
if stripExplicitJsNullableOfRef then stripJsNullable interiorType
@@ -285802,46 +285802,18 @@ let rec recursivelyTransformNamedArgsForMake mapper expr args newtypes coreType
285802285802
(Some coreType)
285803285803
| _ -> (args, newtypes, coreType)
285804285804

285805-
let newtypeToVar newtype type_ =
285806-
let var_desc = Ptyp_var ("type-" ^ newtype) in
285807-
let typ (mapper : Ast_mapper.mapper) typ =
285808-
match typ.ptyp_desc with
285809-
| Ptyp_constr ({txt = Lident name}, _) when name = newtype ->
285810-
{typ with ptyp_desc = var_desc}
285811-
| _ -> Ast_mapper.default_mapper.typ mapper typ
285812-
in
285813-
let mapper = {Ast_mapper.default_mapper with typ} in
285814-
mapper.typ mapper type_
285815-
285816-
let argToType ~newtypes ~(typeConstraints : core_type option) types
285805+
let argToType types
285817285806
((name, default, {ppat_attributes = attrs}, _alias, loc, type_) :
285818285807
arg_label * expression option * pattern * label * 'loc * core_type option)
285819285808
=
285820-
let rec getType name coreType =
285821-
match coreType with
285822-
| {ptyp_desc = Ptyp_arrow (arg, c1, c2)} ->
285823-
if name = arg then Some c1 else getType name c2
285824-
| _ -> None
285825-
in
285826-
let typeConst = Option.bind typeConstraints (getType name) in
285827-
let type_ =
285828-
List.fold_left
285829-
(fun type_ newtype ->
285830-
match (type_, typeConst) with
285831-
| _, Some typ | Some typ, None -> Some (newtypeToVar newtype.txt typ)
285832-
| _ -> None)
285833-
type_ newtypes
285834-
in
285835285809
match (type_, name, default) with
285836285810
| Some type_, name, _ when isOptional name ->
285837285811
(true, getLabel name, attrs, loc, type_) :: types
285838285812
| Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types
285839285813
| None, name, _ when isOptional name ->
285840-
(true, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
285841-
:: types
285814+
(true, getLabel name, attrs, loc, Typ.any ~loc ()) :: types
285842285815
| None, name, _ when isLabelled name ->
285843-
(false, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
285844-
:: types
285816+
(false, getLabel name, attrs, loc, Typ.any ~loc ()) :: types
285845285817
| _ -> types
285846285818

285847285819
let hasDefaultValue nameArgList =
@@ -286121,16 +286093,12 @@ let transformStructureItem ~config mapper item =
286121286093
modifiedBinding binding
286122286094
in
286123286095
(* do stuff here! *)
286124-
let namedArgList, newtypes, typeConstraints =
286096+
let namedArgList, newtypes, _typeConstraints =
286125286097
recursivelyTransformNamedArgsForMake mapper
286126286098
(modifiedBindingOld binding)
286127286099
[] [] None
286128286100
in
286129-
let namedTypeList =
286130-
List.fold_left
286131-
(argToType ~newtypes ~typeConstraints)
286132-
[] namedArgList
286133-
in
286101+
let namedTypeList = List.fold_left argToType [] namedArgList in
286134286102
let vbMatch (name, default, _, alias, loc, _) =
286135286103
let label = getLabel name in
286136286104
match default with
@@ -286323,6 +286291,13 @@ let transformStructureItem ~config mapper item =
286323286291
| _ -> [Typ.any ()]))))
286324286292
expression
286325286293
in
286294+
let expression =
286295+
(* Add new tupes (type a,b,c) to make's definition *)
286296+
newtypes
286297+
|> List.fold_left
286298+
(fun e newtype -> Exp.newtype newtype e)
286299+
expression
286300+
in
286326286301
(* let make = ({id, name, ...}: props<'id, 'name, ...>) => { ... } *)
286327286302
let bindings, newBinding =
286328286303
match recFlag with

0 commit comments

Comments
 (0)