Skip to content

Commit 578c55d

Browse files
committed
Disallow invalid values inside jsx when a fragment is expected
For example, the following used to compile: `jsx('<div>${function() return 42}</div>');` But resulted in a runtime error: > Warning: Functions are not valid as a React child. This may happen if you > return a Component instead of <Component /> from render. Or maybe you meant > to call this function rather than return it. Or, for objects: `jsx('<div>${{test: 42}}</div>');` resulted in: > Uncaught Error: Objects are not valid as a React child (found: object with > keys {test}). If you meant to render a collection of children, > use an array instead.
1 parent dd5c732 commit 578c55d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/lib/react/ReactComponent.hx

+3-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ typedef ReactFragment = EitherType<
118118
ReactElement,
119119
EitherType<
120120
Array<ReactFragment>,
121-
EitherType<String, Float>
121+
EitherType<String,
122+
EitherType<Float, Bool>
123+
>
122124
>
123125
>;

src/lib/react/ReactMacro.hx

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ class ReactMacro
182182
{
183183
return switch (c.value) {
184184
case CText(s): macro @:pos(s.pos) $v{replaceEntities(s.value, s.pos)};
185-
case CExpr(e): e;
185+
case CExpr(e):
186+
macro @:pos(e.pos) (${e} :react.ReactComponent.ReactFragment);
186187
case CNode(n):
187188
var type = switch (n.name.value.split('.')) {
188189
case [tag] if (tag.charAt(0) == tag.charAt(0).toLowerCase()):

0 commit comments

Comments
 (0)