Skip to content

GenType: check annotations also in module types. #5903

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

Merged
merged 1 commit into from
Dec 13, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 30 additions & 8 deletions jscomp/gentype/Annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,41 @@ 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
|| md_type |> moduleTypeCheckAnnotation ~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)
=
Expand Down Expand Up @@ -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) =
Expand Down