Skip to content

Sync the latest syntax #5944

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
Jan 15, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Fix build error where aliasing arguments to `_` in the make function with JSX V4. https://github.com/rescript-lang/syntax/pull/720
- Fix parsing of spread props as an expression in JSX V4 https://github.com/rescript-lang/syntax/pull/721
- Fix dropping attributes from props in make function in JSX V4 https://github.com/rescript-lang/syntax/pull/723
- Fix an issue where error messages related to duplicate props were displayed without a loc and were unclear https://github.com/rescript-lang/syntax/pull/728

# 10.1.0

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 38 additions & 14 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274934,9 +274934,9 @@ let recordFromProps ~loc ~removeKey callArguments =
(* let make = ({id, name, children}: props<'id, 'name, 'children>) *)
let makePropsTypeParamsTvar namedTypeList =
namedTypeList
|> List.filter_map (fun (_isOptional, label, _, _interiorType) ->
|> List.filter_map (fun (_isOptional, label, _, loc, _interiorType) ->
if label = "key" then None
else Some (Typ.var @@ safeTypeFromValue (Labelled label)))
else Some (Typ.var ~loc @@ safeTypeFromValue (Labelled label)))

let stripOption coreType =
match coreType with
Expand All @@ -274960,7 +274960,7 @@ let stripJsNullable coreType =
let makePropsTypeParams ?(stripExplicitOption = false)
?(stripExplicitJsNullableOfRef = false) namedTypeList =
namedTypeList
|> List.filter_map (fun (isOptional, label, _, interiorType) ->
|> List.filter_map (fun (isOptional, label, _, loc, interiorType) ->
if label = "key" then None
(* TODO: Worth thinking how about "ref_" or "_ref" usages *)
else if label = "ref" then
Expand All @@ -274969,7 +274969,7 @@ let makePropsTypeParams ?(stripExplicitOption = false)
For example, if JSX ppx is used for React Native, type would be different.
*)
match interiorType with
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType Location.none)
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType loc)
| _ ->
(* Strip explicit Js.Nullable.t in case of forwardRef *)
if stripExplicitJsNullableOfRef then stripJsNullable interiorType
Expand All @@ -274979,9 +274979,25 @@ let makePropsTypeParams ?(stripExplicitOption = false)
else if isOptional && stripExplicitOption then stripOption interiorType
else Some interiorType)

let makeLabelDecls ~loc namedTypeList =
let makeLabelDecls namedTypeList =
let rec checkDuplicatedLabel l =
let rec mem_label ((_, (la : string), _, _, _) as x) = function
| [] -> false
| (_, (lb : string), _, _, _) :: l -> lb = la || mem_label x l
in
match l with
| [] -> ()
| hd :: tl ->
if mem_label hd tl then
let _, label, _, loc, _ = hd in
React_jsx_common.raiseError ~loc "JSX: found the duplicated prop `%s`"
label
else checkDuplicatedLabel tl
in
let () = namedTypeList |> List.rev |> checkDuplicatedLabel in

namedTypeList
|> List.map (fun (isOptional, label, attrs, interiorType) ->
|> List.map (fun (isOptional, label, attrs, loc, interiorType) ->
if label = "key" then
Type.field ~loc ~attrs:(optionalAttrs @ attrs) {txt = label; loc}
interiorType
Expand All @@ -274993,7 +275009,7 @@ let makeLabelDecls ~loc namedTypeList =
(Typ.var @@ safeTypeFromValue @@ Labelled label))

let makeTypeDecls propsName loc namedTypeList =
let labelDeclList = makeLabelDecls ~loc namedTypeList in
let labelDeclList = makeLabelDecls namedTypeList in
(* 'id, 'className, ... *)
let params =
makePropsTypeParamsTvar namedTypeList
Expand Down Expand Up @@ -275394,17 +275410,22 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
in
match (type_, name, default) with
| Some type_, name, _ when isOptional name ->
(true, getLabel name, attrs, {type_ with ptyp_attributes = optionalAttrs})
( true,
getLabel name,
attrs,
loc,
{type_ with ptyp_attributes = optionalAttrs} )
:: types
| Some type_, name, _ -> (false, getLabel name, attrs, type_) :: types
| Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types
| None, name, _ when isOptional name ->
( true,
getLabel name,
attrs,
loc,
Typ.var ~loc ~attrs:optionalAttrs (safeTypeFromValue name) )
:: types
| None, name, _ when isLabelled name ->
(false, getLabel name, attrs, Typ.var ~loc (safeTypeFromValue name))
(false, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
:: types
| _ -> types

Expand All @@ -275413,10 +275434,12 @@ let argWithDefaultValue (name, default, _, _, _, _) =
| Some default when isOptional name -> Some (getLabel name, default)
| _ -> None

let argToConcreteType types (name, attrs, _loc, type_) =
let argToConcreteType types (name, attrs, loc, type_) =
match name with
| name when isLabelled name -> (false, getLabel name, attrs, type_) :: types
| name when isOptional name -> (true, getLabel name, attrs, type_) :: types
| name when isLabelled name ->
(false, getLabel name, attrs, loc, type_) :: types
| name when isOptional name ->
(true, getLabel name, attrs, loc, type_) :: types
| _ -> types

let check_string_int_attribute_iter =
Expand Down Expand Up @@ -275971,7 +275994,8 @@ let transformSignatureItem ~config _mapper item =
makePropsRecordTypeSig ~coreTypeOfAttr ~typVarsOfCoreType "props"
psig_loc
((* If there is Nolabel arg, regard the type as ref in forwardRef *)
(if !hasForwardRef then [(true, "ref", [], refType Location.none)]
(if !hasForwardRef then
[(true, "ref", [], Location.none, refType Location.none)]
else [])
@ namedTypeList)
in
Expand Down
52 changes: 38 additions & 14 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274934,9 +274934,9 @@ let recordFromProps ~loc ~removeKey callArguments =
(* let make = ({id, name, children}: props<'id, 'name, 'children>) *)
let makePropsTypeParamsTvar namedTypeList =
namedTypeList
|> List.filter_map (fun (_isOptional, label, _, _interiorType) ->
|> List.filter_map (fun (_isOptional, label, _, loc, _interiorType) ->
if label = "key" then None
else Some (Typ.var @@ safeTypeFromValue (Labelled label)))
else Some (Typ.var ~loc @@ safeTypeFromValue (Labelled label)))

let stripOption coreType =
match coreType with
Expand All @@ -274960,7 +274960,7 @@ let stripJsNullable coreType =
let makePropsTypeParams ?(stripExplicitOption = false)
?(stripExplicitJsNullableOfRef = false) namedTypeList =
namedTypeList
|> List.filter_map (fun (isOptional, label, _, interiorType) ->
|> List.filter_map (fun (isOptional, label, _, loc, interiorType) ->
if label = "key" then None
(* TODO: Worth thinking how about "ref_" or "_ref" usages *)
else if label = "ref" then
Expand All @@ -274969,7 +274969,7 @@ let makePropsTypeParams ?(stripExplicitOption = false)
For example, if JSX ppx is used for React Native, type would be different.
*)
match interiorType with
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType Location.none)
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType loc)
| _ ->
(* Strip explicit Js.Nullable.t in case of forwardRef *)
if stripExplicitJsNullableOfRef then stripJsNullable interiorType
Expand All @@ -274979,9 +274979,25 @@ let makePropsTypeParams ?(stripExplicitOption = false)
else if isOptional && stripExplicitOption then stripOption interiorType
else Some interiorType)

let makeLabelDecls ~loc namedTypeList =
let makeLabelDecls namedTypeList =
let rec checkDuplicatedLabel l =
let rec mem_label ((_, (la : string), _, _, _) as x) = function
| [] -> false
| (_, (lb : string), _, _, _) :: l -> lb = la || mem_label x l
in
match l with
| [] -> ()
| hd :: tl ->
if mem_label hd tl then
let _, label, _, loc, _ = hd in
React_jsx_common.raiseError ~loc "JSX: found the duplicated prop `%s`"
label
else checkDuplicatedLabel tl
in
let () = namedTypeList |> List.rev |> checkDuplicatedLabel in

namedTypeList
|> List.map (fun (isOptional, label, attrs, interiorType) ->
|> List.map (fun (isOptional, label, attrs, loc, interiorType) ->
if label = "key" then
Type.field ~loc ~attrs:(optionalAttrs @ attrs) {txt = label; loc}
interiorType
Expand All @@ -274993,7 +275009,7 @@ let makeLabelDecls ~loc namedTypeList =
(Typ.var @@ safeTypeFromValue @@ Labelled label))

let makeTypeDecls propsName loc namedTypeList =
let labelDeclList = makeLabelDecls ~loc namedTypeList in
let labelDeclList = makeLabelDecls namedTypeList in
(* 'id, 'className, ... *)
let params =
makePropsTypeParamsTvar namedTypeList
Expand Down Expand Up @@ -275394,17 +275410,22 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
in
match (type_, name, default) with
| Some type_, name, _ when isOptional name ->
(true, getLabel name, attrs, {type_ with ptyp_attributes = optionalAttrs})
( true,
getLabel name,
attrs,
loc,
{type_ with ptyp_attributes = optionalAttrs} )
:: types
| Some type_, name, _ -> (false, getLabel name, attrs, type_) :: types
| Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types
| None, name, _ when isOptional name ->
( true,
getLabel name,
attrs,
loc,
Typ.var ~loc ~attrs:optionalAttrs (safeTypeFromValue name) )
:: types
| None, name, _ when isLabelled name ->
(false, getLabel name, attrs, Typ.var ~loc (safeTypeFromValue name))
(false, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
:: types
| _ -> types

Expand All @@ -275413,10 +275434,12 @@ let argWithDefaultValue (name, default, _, _, _, _) =
| Some default when isOptional name -> Some (getLabel name, default)
| _ -> None

let argToConcreteType types (name, attrs, _loc, type_) =
let argToConcreteType types (name, attrs, loc, type_) =
match name with
| name when isLabelled name -> (false, getLabel name, attrs, type_) :: types
| name when isOptional name -> (true, getLabel name, attrs, type_) :: types
| name when isLabelled name ->
(false, getLabel name, attrs, loc, type_) :: types
| name when isOptional name ->
(true, getLabel name, attrs, loc, type_) :: types
| _ -> types

let check_string_int_attribute_iter =
Expand Down Expand Up @@ -275971,7 +275994,8 @@ let transformSignatureItem ~config _mapper item =
makePropsRecordTypeSig ~coreTypeOfAttr ~typVarsOfCoreType "props"
psig_loc
((* If there is Nolabel arg, regard the type as ref in forwardRef *)
(if !hasForwardRef then [(true, "ref", [], refType Location.none)]
(if !hasForwardRef then
[(true, "ref", [], Location.none, refType Location.none)]
else [])
@ namedTypeList)
in
Expand Down
52 changes: 38 additions & 14 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -285318,9 +285318,9 @@ let recordFromProps ~loc ~removeKey callArguments =
(* let make = ({id, name, children}: props<'id, 'name, 'children>) *)
let makePropsTypeParamsTvar namedTypeList =
namedTypeList
|> List.filter_map (fun (_isOptional, label, _, _interiorType) ->
|> List.filter_map (fun (_isOptional, label, _, loc, _interiorType) ->
if label = "key" then None
else Some (Typ.var @@ safeTypeFromValue (Labelled label)))
else Some (Typ.var ~loc @@ safeTypeFromValue (Labelled label)))

let stripOption coreType =
match coreType with
Expand All @@ -285344,7 +285344,7 @@ let stripJsNullable coreType =
let makePropsTypeParams ?(stripExplicitOption = false)
?(stripExplicitJsNullableOfRef = false) namedTypeList =
namedTypeList
|> List.filter_map (fun (isOptional, label, _, interiorType) ->
|> List.filter_map (fun (isOptional, label, _, loc, interiorType) ->
if label = "key" then None
(* TODO: Worth thinking how about "ref_" or "_ref" usages *)
else if label = "ref" then
Expand All @@ -285353,7 +285353,7 @@ let makePropsTypeParams ?(stripExplicitOption = false)
For example, if JSX ppx is used for React Native, type would be different.
*)
match interiorType with
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType Location.none)
| {ptyp_desc = Ptyp_var "ref"} -> Some (refType loc)
| _ ->
(* Strip explicit Js.Nullable.t in case of forwardRef *)
if stripExplicitJsNullableOfRef then stripJsNullable interiorType
Expand All @@ -285363,9 +285363,25 @@ let makePropsTypeParams ?(stripExplicitOption = false)
else if isOptional && stripExplicitOption then stripOption interiorType
else Some interiorType)

let makeLabelDecls ~loc namedTypeList =
let makeLabelDecls namedTypeList =
let rec checkDuplicatedLabel l =
let rec mem_label ((_, (la : string), _, _, _) as x) = function
| [] -> false
| (_, (lb : string), _, _, _) :: l -> lb = la || mem_label x l
in
match l with
| [] -> ()
| hd :: tl ->
if mem_label hd tl then
let _, label, _, loc, _ = hd in
React_jsx_common.raiseError ~loc "JSX: found the duplicated prop `%s`"
label
else checkDuplicatedLabel tl
in
let () = namedTypeList |> List.rev |> checkDuplicatedLabel in

namedTypeList
|> List.map (fun (isOptional, label, attrs, interiorType) ->
|> List.map (fun (isOptional, label, attrs, loc, interiorType) ->
if label = "key" then
Type.field ~loc ~attrs:(optionalAttrs @ attrs) {txt = label; loc}
interiorType
Expand All @@ -285377,7 +285393,7 @@ let makeLabelDecls ~loc namedTypeList =
(Typ.var @@ safeTypeFromValue @@ Labelled label))

let makeTypeDecls propsName loc namedTypeList =
let labelDeclList = makeLabelDecls ~loc namedTypeList in
let labelDeclList = makeLabelDecls namedTypeList in
(* 'id, 'className, ... *)
let params =
makePropsTypeParamsTvar namedTypeList
Expand Down Expand Up @@ -285778,17 +285794,22 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
in
match (type_, name, default) with
| Some type_, name, _ when isOptional name ->
(true, getLabel name, attrs, {type_ with ptyp_attributes = optionalAttrs})
( true,
getLabel name,
attrs,
loc,
{type_ with ptyp_attributes = optionalAttrs} )
:: types
| Some type_, name, _ -> (false, getLabel name, attrs, type_) :: types
| Some type_, name, _ -> (false, getLabel name, attrs, loc, type_) :: types
| None, name, _ when isOptional name ->
( true,
getLabel name,
attrs,
loc,
Typ.var ~loc ~attrs:optionalAttrs (safeTypeFromValue name) )
:: types
| None, name, _ when isLabelled name ->
(false, getLabel name, attrs, Typ.var ~loc (safeTypeFromValue name))
(false, getLabel name, attrs, loc, Typ.var ~loc (safeTypeFromValue name))
:: types
| _ -> types

Expand All @@ -285797,10 +285818,12 @@ let argWithDefaultValue (name, default, _, _, _, _) =
| Some default when isOptional name -> Some (getLabel name, default)
| _ -> None

let argToConcreteType types (name, attrs, _loc, type_) =
let argToConcreteType types (name, attrs, loc, type_) =
match name with
| name when isLabelled name -> (false, getLabel name, attrs, type_) :: types
| name when isOptional name -> (true, getLabel name, attrs, type_) :: types
| name when isLabelled name ->
(false, getLabel name, attrs, loc, type_) :: types
| name when isOptional name ->
(true, getLabel name, attrs, loc, type_) :: types
| _ -> types

let check_string_int_attribute_iter =
Expand Down Expand Up @@ -286355,7 +286378,8 @@ let transformSignatureItem ~config _mapper item =
makePropsRecordTypeSig ~coreTypeOfAttr ~typVarsOfCoreType "props"
psig_loc
((* If there is Nolabel arg, regard the type as ref in forwardRef *)
(if !hasForwardRef then [(true, "ref", [], refType Location.none)]
(if !hasForwardRef then
[(true, "ref", [], Location.none, refType Location.none)]
else [])
@ namedTypeList)
in
Expand Down