diff --git a/CHANGELOG.md b/CHANGELOG.md index a109a16b62..d3c24b7eaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ These are only breaking changes for unformatted code. - Fix parsing/printing uncurried functions with type parameters https://github.com/rescript-lang/rescript-compiler/pull/5849 - Fix compiler ppx issue when combining `async` and uncurried application https://github.com/rescript-lang/rescript-compiler/pull/5856 - Fix issue where the internal representation of uncurried types would leak when a non-function is applied in a curried way https://github.com/rescript-lang/rescript-compiler/pull/5892 +- 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 #### :nail_care: Polish diff --git a/jscomp/gentype/Annotation.ml b/jscomp/gentype/Annotation.ml index 5425982cc0..6d0c89f715 100644 --- a/jscomp/gentype/Annotation.ml +++ b/jscomp/gentype/Annotation.ml @@ -151,6 +151,16 @@ let rec moduleTypeCheckAnnotation ~checkAnnotation -> false +and moduleTypeDeclarationCheckAnnotation ~checkAnnotation + ({mtd_type; mtd_attributes; mtd_loc = loc} : + Typedtree.module_type_declaration) = + mtd_attributes |> checkAnnotation ~loc + || + match mtd_type with + | None -> false + | Some module_type -> + module_type |> moduleTypeCheckAnnotation ~checkAnnotation + and moduleDeclarationCheckAnnotation ~checkAnnotation ({md_attributes; md_type; md_loc = loc} : Typedtree.module_declaration) = md_attributes |> checkAnnotation ~loc @@ -158,19 +168,24 @@ and moduleDeclarationCheckAnnotation ~checkAnnotation and signatureItemCheckAnnotation ~checkAnnotation (signatureItem : Typedtree.signature_item) = - match signatureItem with - | {Typedtree.sig_desc = Typedtree.Tsig_type (_, typeDeclarations)} -> + match signatureItem.sig_desc with + | Tsig_type (_, typeDeclarations) -> typeDeclarations |> List.exists (fun ({typ_attributes; typ_loc = loc} : Typedtree.type_declaration) -> typ_attributes |> checkAnnotation ~loc) - | {sig_desc = Tsig_value {val_attributes; val_loc = loc}} -> + | Tsig_value {val_attributes; val_loc = loc} -> val_attributes |> checkAnnotation ~loc - | {sig_desc = Tsig_module moduleDeclaration} -> + | Tsig_module moduleDeclaration -> moduleDeclaration |> moduleDeclarationCheckAnnotation ~checkAnnotation - | {sig_desc = Tsig_attribute attribute; sig_loc = loc} -> - [attribute] |> checkAnnotation ~loc - | _ -> false + | Tsig_attribute attribute -> + [attribute] |> checkAnnotation ~loc:signatureItem.sig_loc + | Tsig_modtype moduleTypeDeclaration -> + moduleTypeDeclaration + |> moduleTypeDeclarationCheckAnnotation ~checkAnnotation + | Tsig_typext _ | Tsig_exception _ | Tsig_recmodule _ | Tsig_open _ + | Tsig_include _ | Tsig_class _ | Tsig_class_type _ -> + false and signatureCheckAnnotation ~checkAnnotation (signature : Typedtree.signature) = @@ -200,7 +215,14 @@ let rec structureItemCheckAnnotation ~checkAnnotation | Tstr_include {incl_attributes; incl_mod; incl_loc = loc} -> incl_attributes |> checkAnnotation ~loc || incl_mod |> moduleExprCheckAnnotation ~checkAnnotation - | _ -> false + | Tstr_modtype moduleTypeDeclaration -> + moduleTypeDeclaration + |> moduleTypeDeclarationCheckAnnotation ~checkAnnotation + | Tstr_attribute attribute -> + [attribute] |> checkAnnotation ~loc:structureItem.str_loc + | Tstr_eval _ | Tstr_typext _ | Tstr_exception _ | Tstr_open _ | Tstr_class _ + | Tstr_class_type _ -> + false and moduleExprCheckAnnotation ~checkAnnotation (moduleExpr : Typedtree.module_expr) =