Skip to content
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 @@ -28,6 +28,7 @@
- Fix exponential notation syntax. https://github.com/rescript-lang/rescript/pull/7174
- Fix bug where a ref assignment is moved ouside a conditional. https://github.com/rescript-lang/rescript/pull/7176
- Fix nullable to opt conversion. https://github.com/rescript-lang/rescript/pull/7193
- Raise error when defining external React components with `@react.componentWithProps`. https://github.com/rescript-lang/rescript/pull/7217

#### :house: Internal

Expand Down
18 changes: 15 additions & 3 deletions compiler/syntax/src/jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1286,9 +1286,21 @@ let transform_structure_item ~config item =
pstr_desc =
Pstr_primitive ({pval_attributes; pval_type} as value_description);
} as pstr -> (
match List.filter Jsx_common.has_attr pval_attributes with
| [] -> [item]
| [_] ->
match
( List.filter Jsx_common.has_attr pval_attributes,
List.filter Jsx_common.has_attr_with_props pval_attributes )
with
| [], [] -> [item]
| _, [_] ->
Jsx_common.raise_error ~loc:pstr_loc
"Components cannot be defined as externals when using \
@react.componentWithProps.\n\n\
If you intended to define an external for a React component using a \
props type,\n\
use the type React.component<props> instead.\n\
Alternatively, use @react.component for an external definition with \
labeled arguments."
| [_], [] ->
check_multiple_components ~config ~loc:pstr_loc;
check_string_int_attribute_iter.structure_item
check_string_int_attribute_iter item;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

We've found a bug for you!
/.../fixtures/react_component_with_props_external.res:1:1-2:40

1 │ @react.componentWithProps
2 │ external make: React.element = "default"
3 │

Components cannot be defined as externals when using @react.componentWithProps.

If you intended to define an external for a React component using a props type,
use the type React.component<props> instead.
Alternatively, use @react.component for an external definition with labeled arguments.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@react.componentWithProps
external make: React.element = "default"