From 431efa34b9042e07865e6e4573c716a0a5825628 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 3 Nov 2022 14:14:58 +0100 Subject: [PATCH] Adapt command to create interface files to latest JSX V4 Fixes https://github.com/rescript-lang/rescript-vscode/issues/617 --- CHANGELOG.md | 2 ++ analysis/src/CreateInterface.ml | 20 +++++++++++++------- analysis/tests/src/JsxV4.res | 6 ++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 926ec5c52..9ee5515ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ - Fix issue where doc comment is not shown on hover in case of shadowed identifier (in particular for JSX V4 components which shadow `make`) https://github.com/rescript-lang/rescript-vscode/issues/621 +- Adapt command to create interface files to latest JSX V4 (no key prop, possibly empty record) https://github.com/rescript-lang/rescript-vscode/issues/617 + ## v1.8.2 #### :rocket: New Feature diff --git a/analysis/src/CreateInterface.ml b/analysis/src/CreateInterface.ml index 07b96d153..7aafb5e49 100644 --- a/analysis/src/CreateInterface.ml +++ b/analysis/src/CreateInterface.ml @@ -240,16 +240,19 @@ let printSignature ~extractor ~signature = ( propsId, { type_params; - type_kind = Type_record (labelDecls, Record_optional_labels optLbls); + type_kind = Type_record (labelDecls, recordRepresentation); }, _ ) :: Sig_value (makeId (* make *), makeValueDesc) :: rest when Ident.name propsId = "props" && getComponentTypeV4 makeValueDesc.val_type <> None - && optLbls |> List.mem "key" -> + && + match recordRepresentation with + | Record_optional_labels _ -> true + | _ -> labelDecls = [] (* empty record *) -> (* PPX V4 component declaration: - type props = {..., key?: _} + type props = {...} let v = ... *) let newItemStr = @@ -268,15 +271,18 @@ let printSignature ~extractor ~signature = in let lblName = labelDecl.ld_id |> Ident.name in let lbl = + let optLbls = + match recordRepresentation with + | Record_optional_labels optLbls -> optLbls + | _ -> [] + in if List.mem lblName optLbls then Asttypes.Optional lblName else Labelled lblName in - if lblName = "key" then mkFunType rest - else - {retType with desc = Tarrow (lbl, propType, mkFunType rest, Cok)} + {retType with desc = Tarrow (lbl, propType, mkFunType rest, Cok)} in let funType = - if List.length labelDecls = 1 (* No props: only "key "*) then + if List.length labelDecls = 0 (* No props *) then let tUnit = Ctype.newconstr (Path.Pident (Ident.create "unit")) [] in diff --git a/analysis/tests/src/JsxV4.res b/analysis/tests/src/JsxV4.res index d23b651ba..a5f2c5d1b 100644 --- a/analysis/tests/src/JsxV4.res +++ b/analysis/tests/src/JsxV4.res @@ -14,3 +14,9 @@ let _ = let _ = // ^hov + + +module MM = { + @react.component + let make = () => React.null +}