Skip to content

Commit 425cb6c

Browse files
committed
Ensure individual prop typing, allowing abstract props to do their magic
1 parent ce79358 commit 425cb6c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/lib/react/ReactMacro.hx

+17-8
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,24 @@ class ReactMacro
115115
};
116116
}
117117

118-
static function typeChecker(type:Expr, nodePos:Position, isHtml:Bool)
118+
static function typeChecker(type:Expr, nodePos:Position, isHtml:Bool):StringAt->Expr->Expr
119119
{
120-
function propsFor(placeholder:Expr):StringAt->Expr->Void
120+
function propsFor(placeholder:Expr):StringAt->Expr->Expr
121121
{
122122
placeholder = Context.storeTypedExpr(Context.typeExpr(placeholder));
123123

124124
return function (name:StringAt, value:Expr) {
125125
var field = name.value;
126126
var target = macro @:pos(name.pos) $placeholder.$field;
127127

128-
Context.typeof(macro @:pos(value.pos) {
128+
var t = Context.typeof(macro @:pos(value.pos) {
129129
var __pseudo = $target;
130130
__pseudo = $value;
131131
});
132+
133+
var ct = haxe.macro.TypeTools.toComplexType(t);
134+
if (ct == null) return value;
135+
return macro @:pos(value.pos) ($value :$ct);
132136
}
133137
}
134138

@@ -149,12 +153,15 @@ class ReactMacro
149153
}
150154

151155
return isHtml
152-
? function(_, _) {}
156+
? function(_, e:Expr) return e
153157
: switch (t) {
154158
case TFun(args, _):
155159
switch (args) {
156160
case []:
157-
function (_, e:Expr) e.reject('no props allowed here');
161+
function (_, e:Expr) {
162+
e.reject('no props allowed here');
163+
return e;
164+
}
158165

159166
case [v]:
160167
propsFor(macro @:pos(type.pos) {
@@ -168,7 +175,7 @@ class ReactMacro
168175
}
169176

170177
case TInst(_.toString() => "String", []):
171-
function(_, _) {};
178+
function(_, e:Expr) return e;
172179

173180
default:
174181
propsFor(macro @:pos(type.pos) {
@@ -204,8 +211,10 @@ class ReactMacro
204211

205212
function add(name:StringAt, e:Expr)
206213
{
207-
checkProp(name, e);
208-
attrs.push({ field: name.value, expr: e });
214+
attrs.push({
215+
field: name.value,
216+
expr: checkProp(name, e)
217+
});
209218
}
210219

211220
for (attr in n.attributes)

0 commit comments

Comments
 (0)