From 09a884524eb0fee6bc4b8224da33a9587211cf4c Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 12 Oct 2022 09:38:36 +0200 Subject: [PATCH 1/3] Emit an error when a @string or @int attribute is used in V4. Fixes https://github.com/rescript-lang/rescript-compiler/issues/5724 --- cli/reactjs_jsx_v4.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cli/reactjs_jsx_v4.ml b/cli/reactjs_jsx_v4.ml index 8303ff85..d6538eb8 100644 --- a/cli/reactjs_jsx_v4.ml +++ b/cli/reactjs_jsx_v4.ml @@ -708,7 +708,19 @@ let argToConcreteType types (name, _loc, type_) = | name when isOptional name -> (true, getLabel name, [], type_) :: types | _ -> types +let check_string_int_attribute_iter = + let attribute _ ({txt; loc}, _) = + if txt = "string" || txt = "int" then + React_jsx_common.raiseError ~loc + "@string and @int attributes not supported. See \ + https://github.com/rescript-lang/rescript-compiler/issues/5724" + in + + {Ast_iterator.default_iterator with attribute} + let transformStructureItem ~config mapper item = + check_string_int_attribute_iter.structure_item check_string_int_attribute_iter + item; match item with (* external *) | { @@ -1158,6 +1170,8 @@ let transformStructureItem ~config mapper item = | _ -> [item] let transformSignatureItem ~config _mapper item = + check_string_int_attribute_iter.signature_item check_string_int_attribute_iter + item; match item with | { psig_loc; From f08d1311d434032ebd0e3de402dbb2d2d2f8eb21 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 12 Oct 2022 09:41:20 +0200 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f4856d2..5b0954ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - Fix printing of comments inside JSX tag https://github.com/rescript-lang/syntax/pull/664 - Fix issue where formatter erases tail comments inside JSX tag https://github.com/rescript-lang/syntax/issues/663 - Fix issue where the JSX prop has type annotation of the first class module https://github.com/rescript-lang/syntax/pull/666 +- Emit an error when a `@string` or `@int` attribute is used in a V4 component https://github.com/rescript-lang/rescript-compiler/issues/5724 #### :eyeglasses: Spec Compliance From 6d493d1e97787ee02b297c51f41d6e1460c2a896 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 12 Oct 2022 09:47:33 +0200 Subject: [PATCH 3/3] Only fire where a `@react.component` is encountered. --- cli/reactjs_jsx_v4.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/reactjs_jsx_v4.ml b/cli/reactjs_jsx_v4.ml index d6538eb8..e6876391 100644 --- a/cli/reactjs_jsx_v4.ml +++ b/cli/reactjs_jsx_v4.ml @@ -719,8 +719,6 @@ let check_string_int_attribute_iter = {Ast_iterator.default_iterator with attribute} let transformStructureItem ~config mapper item = - check_string_int_attribute_iter.structure_item check_string_int_attribute_iter - item; match item with (* external *) | { @@ -736,6 +734,8 @@ let transformStructureItem ~config mapper item = React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc else ( config.hasReactComponent <- true; + check_string_int_attribute_iter.structure_item + check_string_int_attribute_iter item; let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) = match ptyp_desc with | Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest)) @@ -1170,8 +1170,6 @@ let transformStructureItem ~config mapper item = | _ -> [item] let transformSignatureItem ~config _mapper item = - check_string_int_attribute_iter.signature_item check_string_int_attribute_iter - item; match item with | { psig_loc; @@ -1184,6 +1182,8 @@ let transformSignatureItem ~config _mapper item = if config.React_jsx_common.hasReactComponent then React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc else config.hasReactComponent <- true; + check_string_int_attribute_iter.signature_item + check_string_int_attribute_iter item; let hasForwardRef = ref false in let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) = match ptyp_desc with