Skip to content

GenType: check annotations also in module types. #6026

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
Mar 3, 2023
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 @@ -38,6 +38,7 @@
- Fix formatting of `switch` expressions that contain braced `cases` inside https://github.com/rescript-lang/syntax/pull/735
- Fix formatting of props spread for multiline JSX expression https://github.com/rescript-lang/syntax/pull/736
- Support `@gentype.import` as an alias to `@genType.import` in the compiler https://github.com/rescript-lang/rescript-compiler/pull/6021
- 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

#### :rocket: New Feature

Expand Down
52 changes: 37 additions & 15 deletions jscomp/gentype/Annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,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 All @@ -183,28 +198,35 @@ and signatureCheckAnnotation ~checkAnnotation (signature : Typedtree.signature)

let rec structureItemCheckAnnotation ~checkAnnotation
(structureItem : Typedtree.structure_item) =
match structureItem with
| { Typedtree.str_desc = Typedtree.Tstr_type (_, typeDeclarations) } ->
match structureItem.str_desc with
| Tstr_type (_, typeDeclarations) ->
typeDeclarations
|> List.exists
(fun ({ typ_attributes; typ_loc = loc } : Typedtree.type_declaration)
-> typ_attributes |> checkAnnotation ~loc)
| { str_desc = Tstr_value (_loc, valueBindings) } ->
| Tstr_value (_loc, valueBindings) ->
valueBindings
|> List.exists
(fun ({ vb_attributes; vb_loc = loc } : Typedtree.value_binding) ->
vb_attributes |> checkAnnotation ~loc)
| { str_desc = Tstr_primitive { val_attributes; val_loc = loc } } ->
| Tstr_primitive { val_attributes; val_loc = loc } ->
val_attributes |> checkAnnotation ~loc
| { str_desc = Tstr_module moduleBinding } ->
| Tstr_module moduleBinding ->
moduleBinding |> moduleBindingCheckAnnotation ~checkAnnotation
| { str_desc = Tstr_recmodule moduleBindings } ->
| Tstr_recmodule moduleBindings ->
moduleBindings
|> List.exists (moduleBindingCheckAnnotation ~checkAnnotation)
| { str_desc = Tstr_include { incl_attributes; incl_mod; incl_loc = loc } } ->
| 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
52 changes: 37 additions & 15 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -239714,26 +239714,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 All @@ -239742,28 +239757,35 @@ and signatureCheckAnnotation ~checkAnnotation (signature : Typedtree.signature)

let rec structureItemCheckAnnotation ~checkAnnotation
(structureItem : Typedtree.structure_item) =
match structureItem with
| { Typedtree.str_desc = Typedtree.Tstr_type (_, typeDeclarations) } ->
match structureItem.str_desc with
| Tstr_type (_, typeDeclarations) ->
typeDeclarations
|> List.exists
(fun ({ typ_attributes; typ_loc = loc } : Typedtree.type_declaration)
-> typ_attributes |> checkAnnotation ~loc)
| { str_desc = Tstr_value (_loc, valueBindings) } ->
| Tstr_value (_loc, valueBindings) ->
valueBindings
|> List.exists
(fun ({ vb_attributes; vb_loc = loc } : Typedtree.value_binding) ->
vb_attributes |> checkAnnotation ~loc)
| { str_desc = Tstr_primitive { val_attributes; val_loc = loc } } ->
| Tstr_primitive { val_attributes; val_loc = loc } ->
val_attributes |> checkAnnotation ~loc
| { str_desc = Tstr_module moduleBinding } ->
| Tstr_module moduleBinding ->
moduleBinding |> moduleBindingCheckAnnotation ~checkAnnotation
| { str_desc = Tstr_recmodule moduleBindings } ->
| Tstr_recmodule moduleBindings ->
moduleBindings
|> List.exists (moduleBindingCheckAnnotation ~checkAnnotation)
| { str_desc = Tstr_include { incl_attributes; incl_mod; incl_loc = loc } } ->
| 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