Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit bf949d7

Browse files
authored
Emit an error when a @string or @int attribute is used in V4. (#672)
* Emit an error when a @string or @int attribute is used in V4. Fixes rescript-lang/rescript#5724 * Update CHANGELOG.md * Only fire where a `@react.component` is encountered.
1 parent a40b8b6 commit bf949d7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
- Fix printing of comments inside JSX tag https://github.com/rescript-lang/syntax/pull/664
3535
- Fix issue where formatter erases tail comments inside JSX tag https://github.com/rescript-lang/syntax/issues/663
3636
- Fix issue where the JSX prop has type annotation of the first class module https://github.com/rescript-lang/syntax/pull/666
37+
- Emit an error when a `@string` or `@int` attribute is used in a V4 component https://github.com/rescript-lang/rescript-compiler/issues/5724
3738

3839
#### :eyeglasses: Spec Compliance
3940

cli/reactjs_jsx_v4.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,16 @@ let argToConcreteType types (name, _loc, type_) =
708708
| name when isOptional name -> (true, getLabel name, [], type_) :: types
709709
| _ -> types
710710

711+
let check_string_int_attribute_iter =
712+
let attribute _ ({txt; loc}, _) =
713+
if txt = "string" || txt = "int" then
714+
React_jsx_common.raiseError ~loc
715+
"@string and @int attributes not supported. See \
716+
https://github.com/rescript-lang/rescript-compiler/issues/5724"
717+
in
718+
719+
{Ast_iterator.default_iterator with attribute}
720+
711721
let transformStructureItem ~config mapper item =
712722
match item with
713723
(* external *)
@@ -724,6 +734,8 @@ let transformStructureItem ~config mapper item =
724734
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
725735
else (
726736
config.hasReactComponent <- true;
737+
check_string_int_attribute_iter.structure_item
738+
check_string_int_attribute_iter item;
727739
let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) =
728740
match ptyp_desc with
729741
| Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest))
@@ -1170,6 +1182,8 @@ let transformSignatureItem ~config _mapper item =
11701182
if config.React_jsx_common.hasReactComponent then
11711183
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
11721184
else config.hasReactComponent <- true;
1185+
check_string_int_attribute_iter.signature_item
1186+
check_string_int_attribute_iter item;
11731187
let hasForwardRef = ref false in
11741188
let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) =
11751189
match ptyp_desc with

0 commit comments

Comments
 (0)