Skip to content

Commit 8f35e4f

Browse files
committed
GenType: check annotations also in module types.
1 parent 6c4514c commit 8f35e4f

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ subset of the arguments, and return a curried type with the remaining ones https
2323
- Parser/Printer: unify uncurried functions of arity 0, and of arity 1 taking unit. There's now only arity 1 in the source language. https://github.com/rescript-lang/rescript-compiler/pull/5825
2424
- Add support for default arguments in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5835
2525
- Inline uncurried application when it is safe https://github.com/rescript-lang/rescript-compiler/pull/5847
26+
- 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
2627

2728
#### :boom: Breaking Change
2829

jscomp/gentype/Annotation.ml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,41 @@ let rec moduleTypeCheckAnnotation ~checkAnnotation
151151
->
152152
false
153153

154+
and moduleTypeDeclarationCheckAnnotation ~checkAnnotation
155+
({mtd_type; mtd_attributes; mtd_loc = loc} :
156+
Typedtree.module_type_declaration) =
157+
mtd_attributes |> checkAnnotation ~loc
158+
||
159+
match mtd_type with
160+
| None -> false
161+
| Some module_type ->
162+
module_type |> moduleTypeCheckAnnotation ~checkAnnotation
163+
154164
and moduleDeclarationCheckAnnotation ~checkAnnotation
155165
({md_attributes; md_type; md_loc = loc} : Typedtree.module_declaration) =
156166
md_attributes |> checkAnnotation ~loc
157167
|| md_type |> moduleTypeCheckAnnotation ~checkAnnotation
158168

159169
and signatureItemCheckAnnotation ~checkAnnotation
160170
(signatureItem : Typedtree.signature_item) =
161-
match signatureItem with
162-
| {Typedtree.sig_desc = Typedtree.Tsig_type (_, typeDeclarations)} ->
171+
match signatureItem.sig_desc with
172+
| Tsig_type (_, typeDeclarations) ->
163173
typeDeclarations
164174
|> List.exists
165175
(fun ({typ_attributes; typ_loc = loc} : Typedtree.type_declaration) ->
166176
typ_attributes |> checkAnnotation ~loc)
167-
| {sig_desc = Tsig_value {val_attributes; val_loc = loc}} ->
177+
| Tsig_value {val_attributes; val_loc = loc} ->
168178
val_attributes |> checkAnnotation ~loc
169-
| {sig_desc = Tsig_module moduleDeclaration} ->
179+
| Tsig_module moduleDeclaration ->
170180
moduleDeclaration |> moduleDeclarationCheckAnnotation ~checkAnnotation
171-
| {sig_desc = Tsig_attribute attribute; sig_loc = loc} ->
172-
[attribute] |> checkAnnotation ~loc
173-
| _ -> false
181+
| Tsig_attribute attribute ->
182+
[attribute] |> checkAnnotation ~loc:signatureItem.sig_loc
183+
| Tsig_modtype moduleTypeDeclaration ->
184+
moduleTypeDeclaration
185+
|> moduleTypeDeclarationCheckAnnotation ~checkAnnotation
186+
| Tsig_typext _ | Tsig_exception _ | Tsig_recmodule _ | Tsig_open _
187+
| Tsig_include _ | Tsig_class _ | Tsig_class_type _ ->
188+
false
174189

175190
and signatureCheckAnnotation ~checkAnnotation (signature : Typedtree.signature)
176191
=
@@ -200,7 +215,14 @@ let rec structureItemCheckAnnotation ~checkAnnotation
200215
| Tstr_include {incl_attributes; incl_mod; incl_loc = loc} ->
201216
incl_attributes |> checkAnnotation ~loc
202217
|| incl_mod |> moduleExprCheckAnnotation ~checkAnnotation
203-
| _ -> false
218+
| Tstr_modtype moduleTypeDeclaration ->
219+
moduleTypeDeclaration
220+
|> moduleTypeDeclarationCheckAnnotation ~checkAnnotation
221+
| Tstr_attribute attribute ->
222+
[attribute] |> checkAnnotation ~loc:structureItem.str_loc
223+
| Tstr_eval _ | Tstr_typext _ | Tstr_exception _ | Tstr_open _ | Tstr_class _
224+
| Tstr_class_type _ ->
225+
false
204226

205227
and moduleExprCheckAnnotation ~checkAnnotation
206228
(moduleExpr : Typedtree.module_expr) =

0 commit comments

Comments
 (0)