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 2 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,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently fires anywhere.
I guess it can be scoped to fire only under @react.component.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, hadn't seen that before I approved, sorry.
Yes, should be scoped under @react.component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

item;
match item with
(* external *)
| {
Expand Down Expand Up @@ -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;
Expand Down