Skip to content

Commit 0b042c8

Browse files
committed
Adapt command to create interface files to latest JSX V4
Fixes #617
1 parent da80ba2 commit 0b042c8

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
- 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
2020

21+
- 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
22+
2123
## v1.8.2
2224

2325
#### :rocket: New Feature

analysis/src/CreateInterface.ml

+13-7
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,19 @@ let printSignature ~extractor ~signature =
240240
( propsId,
241241
{
242242
type_params;
243-
type_kind = Type_record (labelDecls, Record_optional_labels optLbls);
243+
type_kind = Type_record (labelDecls, recordRepresentation);
244244
},
245245
_ )
246246
:: Sig_value (makeId (* make *), makeValueDesc)
247247
:: rest
248248
when Ident.name propsId = "props"
249249
&& getComponentTypeV4 makeValueDesc.val_type <> None
250-
&& optLbls |> List.mem "key" ->
250+
&&
251+
match recordRepresentation with
252+
| Record_optional_labels _ -> true
253+
| _ -> labelDecls = [] (* empty record *) ->
251254
(* PPX V4 component declaration:
252-
type props = {..., key?: _}
255+
type props = {...}
253256
let v = ...
254257
*)
255258
let newItemStr =
@@ -268,15 +271,18 @@ let printSignature ~extractor ~signature =
268271
in
269272
let lblName = labelDecl.ld_id |> Ident.name in
270273
let lbl =
274+
let optLbls =
275+
match recordRepresentation with
276+
| Record_optional_labels optLbls -> optLbls
277+
| _ -> []
278+
in
271279
if List.mem lblName optLbls then Asttypes.Optional lblName
272280
else Labelled lblName
273281
in
274-
if lblName = "key" then mkFunType rest
275-
else
276-
{retType with desc = Tarrow (lbl, propType, mkFunType rest, Cok)}
282+
{retType with desc = Tarrow (lbl, propType, mkFunType rest, Cok)}
277283
in
278284
let funType =
279-
if List.length labelDecls = 1 (* No props: only "key "*) then
285+
if List.length labelDecls = 0 (* No props *) then
280286
let tUnit =
281287
Ctype.newconstr (Path.Pident (Ident.create "unit")) []
282288
in

analysis/tests/src/JsxV4.res

+6
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ let _ = <M4 first="abc" />
1414

1515
let _ = <M4 first="abc" />
1616
// ^hov
17+
18+
19+
module MM = {
20+
@react.component
21+
let make = () => React.null
22+
}

0 commit comments

Comments
 (0)