Skip to content
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

Adapt command to create interface files to latest JSX V4 #623

Merged
merged 1 commit into from
Nov 3, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions analysis/src/CreateInterface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions analysis/tests/src/JsxV4.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ let _ = <M4 first="abc" />

let _ = <M4 first="abc" />
// ^hov


module MM = {
@react.component
let make = () => React.null
}