Skip to content

Commit 32fa620

Browse files
authored
Add error using @react.componentWithProps with external (#7217)
* Add error using @react.componentWithProps with external * wildcard pattern * change log * fix error message * update error message
1 parent dfd36a2 commit 32fa620

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- Fix exponential notation syntax. https://github.com/rescript-lang/rescript/pull/7174
3333
- Fix bug where a ref assignment is moved ouside a conditional. https://github.com/rescript-lang/rescript/pull/7176
3434
- Fix nullable to opt conversion. https://github.com/rescript-lang/rescript/pull/7193
35+
- Raise error when defining external React components with `@react.componentWithProps`. https://github.com/rescript-lang/rescript/pull/7217
3536

3637
#### :house: Internal
3738

Diff for: compiler/syntax/src/jsx_v4.ml

+15-3
Original file line numberDiff line numberDiff line change
@@ -1286,9 +1286,21 @@ let transform_structure_item ~config item =
12861286
pstr_desc =
12871287
Pstr_primitive ({pval_attributes; pval_type} as value_description);
12881288
} as pstr -> (
1289-
match List.filter Jsx_common.has_attr pval_attributes with
1290-
| [] -> [item]
1291-
| [_] ->
1289+
match
1290+
( List.filter Jsx_common.has_attr pval_attributes,
1291+
List.filter Jsx_common.has_attr_with_props pval_attributes )
1292+
with
1293+
| [], [] -> [item]
1294+
| _, [_] ->
1295+
Jsx_common.raise_error ~loc:pstr_loc
1296+
"Components cannot be defined as externals when using \
1297+
@react.componentWithProps.\n\n\
1298+
If you intended to define an external for a React component using a \
1299+
props type,\n\
1300+
use the type React.component<props> instead.\n\
1301+
Alternatively, use @react.component for an external definition with \
1302+
labeled arguments."
1303+
| [_], [] ->
12921304
check_multiple_components ~config ~loc:pstr_loc;
12931305
check_string_int_attribute_iter.structure_item
12941306
check_string_int_attribute_iter item;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/react_component_with_props_external.res:1:1-2:40
4+
5+
1 │ [1;[email protected]
6+
2 │ external make: React.element = "default"
7+
3 │
8+
9+
Components cannot be defined as externals when using @react.componentWithProps.
10+
11+
If you intended to define an external for a React component using a props type,
12+
use the type React.component<props> instead.
13+
Alternatively, use @react.component for an external definition with labeled arguments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@react.componentWithProps
2+
external make: React.element = "default"

0 commit comments

Comments
 (0)