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

Emit an error when a @string or @int attribute is used in V4. #672

Merged
merged 3 commits into from
Oct 12, 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 @@ -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

Expand Down
14 changes: 14 additions & 0 deletions cli/reactjs_jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,16 @@ 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 =
match item with
(* external *)
Expand All @@ -724,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))
Expand Down Expand Up @@ -1170,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
Expand Down